class CustomBlock

Defines the custom block entity class.

Plugin annotation


@EntityType(
  id = "custom_block",
  label = @Translation("Custom Block"),
  bundle_label = @Translation("Custom Block type"),
  module = "custom_block",
  controllers = {
    "storage" = "Drupal\custom_block\CustomBlockStorageController",
    "access" = "Drupal\custom_block\CustomBlockAccessController",
    "render" = "Drupal\custom_block\CustomBlockRenderController",
    "form" = {
      "default" = "Drupal\custom_block\CustomBlockFormController"
    },
    "translation" = "Drupal\custom_block\CustomBlockTranslationController"
  },
  base_table = "custom_block",
  revision_table = "custom_block_revision",
  route_base_path = "admin/structure/custom-blocks/manage/{bundle}",
  menu_base_path = "block/%custom_block",
  fieldable = TRUE,
  translatable = TRUE,
  entity_keys = {
    "id" = "id",
    "revision" = "revision_id",
    "bundle" = "type",
    "label" = "info",
    "uuid" = "uuid"
  },
  bundle_keys = {
    "bundle" = "type"
  }
)

Hierarchy

Expanded class hierarchy of CustomBlock

4 files declare their use of CustomBlock
CustomBlockTranslationUITest.php in drupal/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTranslationUITest.php
Contains \Drupal\custom_block\Tests\CustomBlockTranslationUITest.
custom_block.module in drupal/core/modules/block/custom_block/custom_block.module
Allows the creaation of custom blocks through the user interface.
custom_block.pages.inc in drupal/core/modules/block/custom_block/custom_block.pages.inc
Provides page callbacks for custom blocks.
custom_block_test.module in drupal/core/modules/block/custom_block/tests/modules/custom_block_test/custom_block_test.module
A dummy module for testing custom block related hooks.

File

drupal/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php, line 50
Contains \Drupal\custom_block\Plugin\Core\Entity\CustomBlock.

Namespace

Drupal\custom_block\Plugin\Core\Entity
View source
class CustomBlock extends EntityNG implements CustomBlockInterface {

  /**
   * The block ID.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $id;

  /**
   * The block revision ID.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $revision_id;

  /**
   * Indicates whether this is the default block revision.
   *
   * The default revision of a block is the one loaded when no specific revision
   * has been specified. Only default revisions are saved to the block_custom
   * table.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $isDefaultRevision = TRUE;

  /**
   * The block UUID.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $uuid;

  /**
   * The custom block type (bundle).
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $type;

  /**
   * The block language code.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $langcode;

  /**
   * The block description.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $info;

  /**
   * The block revision log message.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $log;

  /**
   * The theme the block is being created in.
   *
   * When creating a new custom block from the block library, the user is
   * redirected to the configure form for that block in the given theme. The
   * theme is stored against the block when the custom block add form is shown.
   *
   * @var string
   */
  protected $theme;

  /**
   * {@inheritdoc}
   */
  public function createDuplicate() {
    $duplicate = parent::createDuplicate();
    $duplicate->revision_id->value = NULL;
    $duplicate->id->value = NULL;
    return $duplicate;
  }

  /**
   * {@inheritdoc}
   */
  public function getRevisionId() {
    return $this->revision_id->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setTheme($theme) {
    $this->theme = $theme;
  }

  /**
   * {@inheritdoc}
   */
  public function getTheme() {
    return $this->theme;
  }

  /**
   * Initialize the object. Invoked upon construction and wake up.
   */
  protected function init() {
    parent::init();

    // We unset all defined properties except theme, so magic getters apply.
    // $this->theme is a special use-case that is only used in the lifecycle of
    // adding a new block using the block library.
    unset($this->id);
    unset($this->info);
    unset($this->revision_id);
    unset($this->log);
    unset($this->uuid);
    unset($this->type);
    unset($this->new);
  }

  /**
   * {@inheritdoc}
   */
  public function uri() {
    return array(
      'path' => 'block/' . $this
        ->id(),
      'options' => array(
        'entity_type' => $this->entityType,
        'entity' => $this,
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getInstances() {
    return entity_load_multiple_by_properties('block', array(
      'plugin' => 'custom_block:' . $this->uuid->value,
    ));
  }

  /**
   * {@inheritdoc}
   */
  public function delete() {
    foreach ($this
      ->getInstances() as $instance) {
      $instance
        ->delete();
    }
    parent::delete();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CustomBlock::$id public property The block ID.
CustomBlock::$info public property The block description.
CustomBlock::$isDefaultRevision public property Indicates whether this is the default block revision. Overrides Entity::$isDefaultRevision
CustomBlock::$langcode public property The block language code. Overrides Entity::$langcode
CustomBlock::$log public property The block revision log message.
CustomBlock::$revision_id public property The block revision ID.
CustomBlock::$theme protected property The theme the block is being created in.
CustomBlock::$type public property The custom block type (bundle).
CustomBlock::$uuid public property The block UUID.
CustomBlock::createDuplicate public function Overrides Entity::createDuplicate(). Overrides EntityNG::createDuplicate
CustomBlock::delete public function Implements \Drupal\Core\Entity\EntityInterface::delete(). Overrides Entity::delete
CustomBlock::getInstances public function Gets the configured instances of this custom block. Overrides CustomBlockInterface::getInstances
CustomBlock::getRevisionId public function Implements \Drupal\Core\Entity\EntityInterface::getRevisionId(). Overrides Entity::getRevisionId
CustomBlock::getTheme public function Gets the theme value. Overrides CustomBlockInterface::getTheme
CustomBlock::init protected function Initialize the object. Invoked upon construction and wake up. Overrides EntityNG::init
CustomBlock::setTheme public function Sets the theme value. Overrides CustomBlockInterface::setTheme
CustomBlock::uri public function Implements \Drupal\Core\Entity\EntityInterface::uri(). Overrides EntityNG::uri
Entity::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
Entity::$entityType protected property The entity type.
Entity::$newRevision protected property Boolean indicating whether a new revision should be created on save.
Entity::access public function Implements \Drupal\Core\TypedData\AccessibleInterface::access(). Overrides AccessibleInterface::access
Entity::enforceIsNew public function Implements \Drupal\Core\Entity\EntityInterface::enforceIsNew(). Overrides EntityInterface::enforceIsNew
Entity::entityInfo public function Implements \Drupal\Core\Entity\EntityInterface::entityInfo(). Overrides EntityInterface::entityInfo
Entity::entityType public function Implements \Drupal\Core\Entity\EntityInterface::entityType(). Overrides EntityInterface::entityType
Entity::getConstraints public function Implements \Drupal\Core\TypedData\TypedDataInterface::getConstraints(). Overrides TypedDataInterface::getConstraints
Entity::getDefinition public function Implements \Drupal\Core\TypedData\TypedDataInterface::getDefinition(). Overrides TypedDataInterface::getDefinition
Entity::getExportProperties public function Implements \Drupal\Core\Entity\EntityInterface::getExportProperties(). Overrides EntityInterface::getExportProperties 1
Entity::getName public function Implements \Drupal\Core\TypedData\TypedDataInterface::getName(). Overrides TypedDataInterface::getName
Entity::getNGEntity public function Implements \Drupal\Core\Entity\EntityInterface::getNGEntity(). Overrides EntityInterface::getNGEntity
Entity::getParent public function Implements \Drupal\Core\TypedData\TypedDataInterface::getParent(). Overrides TypedDataInterface::getParent
Entity::getPropertyPath public function Implements \Drupal\Core\TypedData\TypedDataInterface::getPropertyPath(). Overrides TypedDataInterface::getPropertyPath
Entity::getRoot public function Implements \Drupal\Core\TypedData\TypedDataInterface::getRoot(). Overrides TypedDataInterface::getRoot
Entity::getString public function Implements \Drupal\Core\TypedData\TypedDataInterface::getString(). Overrides TypedDataInterface::getString
Entity::getValue public function Implements \Drupal\Core\TypedData\TypedDataInterface::getValue(). Overrides TypedDataInterface::getValue
Entity::isDefaultRevision public function Implements \Drupal\Core\Entity\EntityInterface::isDefaultRevision(). Overrides EntityInterface::isDefaultRevision 1
Entity::isNew public function Implements \Drupal\Core\Entity\EntityInterface::isNew(). Overrides EntityInterface::isNew 1
Entity::isNewRevision public function Implements \Drupal\Core\Entity\EntityInterface::isNewRevision(). Overrides EntityInterface::isNewRevision
Entity::isTranslatable public function Implements \Drupal\Core\Entity\EntityInterface::isTranslatable(). Overrides EntityInterface::isTranslatable
Entity::onChange public function Implements \Drupal\Core\TypedData\ComplexDataInterface::onChange(). Overrides ComplexDataInterface::onChange
Entity::save public function Implements \Drupal\Core\Entity\EntityInterface::save(). Overrides EntityInterface::save 6
Entity::setContext public function Implements \Drupal\Core\TypedData\TypedDataInterface::setContext(). Overrides TypedDataInterface::setContext
Entity::setNewRevision public function Implements \Drupal\Core\Entity\EntityInterface::setNewRevision(). Overrides EntityInterface::setNewRevision
Entity::setValue public function Implements \Drupal\Core\TypedData\TypedDataInterface::setValue(). Overrides TypedDataInterface::setValue
Entity::uriRelationships public function Returns a list of URI relationships supported by this entity. Overrides EntityInterface::uriRelationships
EntityNG::$bcEntity protected property An instance of the backward compatibility decorator.
EntityNG::$bundle protected property Local cache holding the value of the bundle field.
EntityNG::$fieldDefinitions protected property Local cache for field definitions.
EntityNG::$fields protected property The array of fields, each being an instance of FieldInterface.
EntityNG::$uriPlaceholderReplacements protected property Local cache for URI placeholder substitution values.
EntityNG::$values protected property The plain data values of the contained fields. 3
EntityNG::bundle public function Implements \Drupal\Core\Entity\EntityInterface::bundle(). Overrides Entity::bundle
EntityNG::get public function Implements \Drupal\Core\TypedData\ComplexDataInterface::get(). Overrides Entity::get
EntityNG::getBCEntity public function Overrides Entity::getBCEntity(). Overrides Entity::getBCEntity 2
EntityNG::getIterator public function Implements \IteratorAggregate::getIterator(). Overrides Entity::getIterator
EntityNG::getProperties public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getProperties(). Overrides Entity::getProperties
EntityNG::getPropertyDefinition public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinition(). Overrides Entity::getPropertyDefinition
EntityNG::getPropertyDefinitions public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). Overrides Entity::getPropertyDefinitions
EntityNG::getPropertyValues public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyValues(). Overrides Entity::getPropertyValues
EntityNG::getTranslatedField protected function Gets a translated field.
EntityNG::getTranslation public function Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslation(). Overrides Entity::getTranslation
EntityNG::getTranslationLanguages public function Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages(). Overrides Entity::getTranslationLanguages
EntityNG::getType public function Gets the typed data type of the entity. Overrides Entity::getType
EntityNG::id public function Implements \Drupal\Core\Entity\EntityInterface::id(). Overrides Entity::id 6
EntityNG::isEmpty public function Implements \Drupal\Core\TypedData\ComplexDataInterface::isEmpty(). Overrides Entity::isEmpty
EntityNG::label public function Overrides Entity::label() to access the label field with the new API. Overrides Entity::label 3
EntityNG::language public function Implements \Drupal\Core\TypedData\TranslatableInterface::language(). Overrides Entity::language
EntityNG::set public function Implements \Drupal\Core\TypedData\ComplexDataInterface::set(). Overrides Entity::set
EntityNG::setPropertyValues public function Implements \Drupal\Core\TypedData\ComplexDataInterface::setPropertyValues(). Overrides Entity::setPropertyValues
EntityNG::translations public function Overrides Entity::translations(). Overrides Entity::translations
EntityNG::updateOriginalValues public function Updates the original values with the interim changes.
EntityNG::uriPlaceholderReplacements protected function Returns an array of placeholders for this entity.
EntityNG::uuid public function Overrides Entity::uuid(). Overrides Entity::uuid
EntityNG::validate public function Implements \Drupal\Core\TypedData\TypedDataInterface::validate(). Overrides Entity::validate
EntityNG::__clone public function Magic method: Implements a deep clone.
EntityNG::__construct public function Overrides Entity::__construct(). Overrides Entity::__construct
EntityNG::__get public function Implements the magic method for setting object properties.
EntityNG::__isset public function Implements the magic method for isset().
EntityNG::__set public function Implements the magic method for setting object properties.
EntityNG::__unset public function Implements the magic method for unset.
EntityNG::__wakeup public function Magic __wakeup() implementation.