class Block in Zircon Profile 8.0
Same name in this branch
- 8.0 core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block
- 8.0 core/lib/Drupal/Core/Block/Annotation/Block.php \Drupal\Core\Block\Annotation\Block
- 8.0 core/modules/views/src/Plugin/views/display/Block.php \Drupal\views\Plugin\views\display\Block
- 8.0 core/modules/block/src/Plugin/migrate/source/Block.php \Drupal\block\Plugin\migrate\source\Block
Same name and namespace in other branches
- 8 core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block
Defines a Block configuration entity class.
Plugin annotation
@ConfigEntityType(
id = "block",
label = @Translation("Block"),
handlers = {
"access" = "Drupal\block\BlockAccessControlHandler",
"view_builder" = "Drupal\block\BlockViewBuilder",
"list_builder" = "Drupal\block\BlockListBuilder",
"form" = {
"default" = "Drupal\block\BlockForm",
"delete" = "Drupal\block\Form\BlockDeleteForm"
}
},
admin_permission = "administer blocks",
entity_keys = {
"id" = "id"
},
links = {
"delete-form" = "/admin/structure/block/manage/{block}/delete",
"edit-form" = "/admin/structure/block/manage/{block}"
},
config_export = {
"id",
"theme",
"region",
"weight",
"provider",
"plugin",
"settings",
"visibility",
},
lookup_keys = {
"theme"
}
)
Hierarchy
- class \Drupal\Core\Entity\Entity implements EntityInterface uses RefinableCacheableDependencyTrait, DependencySerializationTrait
- class \Drupal\Core\Config\Entity\ConfigEntityBase implements ConfigEntityInterface uses PluginDependencyTrait
- class \Drupal\block\Entity\Block implements BlockInterface, EntityWithPluginCollectionInterface
- class \Drupal\Core\Config\Entity\ConfigEntityBase implements ConfigEntityInterface uses PluginDependencyTrait
Expanded class hierarchy of Block
17 files declare their use of Block
- AreaEntityTest.php in core/
modules/ views/ src/ Tests/ Handler/ AreaEntityTest.php - Contains \Drupal\views\Tests\Handler\AreaEntityTest.
- AreaEntityUITest.php in core/
modules/ views_ui/ src/ Tests/ AreaEntityUITest.php - Contains \Drupal\views_ui\Tests\AreaEntityUITest.
- block.module in core/
modules/ block/ block.module - Controls the visual building blocks a page is constructed with.
- BlockConfigSchemaTest.php in core/
modules/ block/ src/ Tests/ BlockConfigSchemaTest.php - Contains \Drupal\block\Tests\BlockConfigSchemaTest.
- BlockContextMappingUpdateTest.php in core/
modules/ block/ src/ Tests/ Update/ BlockContextMappingUpdateTest.php - Contains \Drupal\block\Tests\Update\BlockContextMappingUpdateTest.
23 string references to 'Block'
- block.info.yml in core/
modules/ block/ block.info.yml - core/modules/block/block.info.yml
- block.schema.yml in core/
modules/ block/ config/ schema/ block.schema.yml - core/modules/block/config/schema/block.schema.yml
- BlockLibraryController::listBlocks in core/
modules/ block/ src/ Controller/ BlockLibraryController.php - Shows a list of blocks that can be added to a theme's layout.
- BlockListBuilder::buildBlocksForm in core/
modules/ block/ src/ BlockListBuilder.php - Builds the main "Blocks" portion of the form.
- book.schema.yml in core/
modules/ book/ config/ schema/ book.schema.yml - core/modules/book/config/schema/book.schema.yml
File
- core/
modules/ block/ src/ Entity/ Block.php, line 57 - Contains \Drupal\block\Entity\Block.
Namespace
Drupal\block\EntityView source
class Block extends ConfigEntityBase implements BlockInterface, EntityWithPluginCollectionInterface {
/**
* The ID of the block.
*
* @var string
*/
protected $id;
/**
* The plugin instance settings.
*
* @var array
*/
protected $settings = array();
/**
* The region this block is placed in.
*
* @var string
*/
protected $region = self::BLOCK_REGION_NONE;
/**
* The block weight.
*
* @var int
*/
protected $weight;
/**
* The plugin instance ID.
*
* @var string
*/
protected $plugin;
/**
* The visibility settings for this block.
*
* @var array
*/
protected $visibility = [];
/**
* The plugin collection that holds the block plugin for this entity.
*
* @var \Drupal\block\BlockPluginCollection
*/
protected $pluginCollection;
/**
* The available contexts for this block and its visibility conditions.
*
* @var array
*/
protected $contexts = [];
/**
* The visibility collection.
*
* @var \Drupal\Core\Condition\ConditionPluginCollection
*/
protected $visibilityCollection;
/**
* The condition plugin manager.
*
* @var \Drupal\Core\Executable\ExecutableManagerInterface
*/
protected $conditionPluginManager;
/**
* The theme that includes the block plugin for this entity.
*
* @var string
*/
protected $theme;
/**
* {@inheritdoc}
*/
public function getPlugin() {
return $this
->getPluginCollection()
->get($this->plugin);
}
/**
* Encapsulates the creation of the block's LazyPluginCollection.
*
* @return \Drupal\Component\Plugin\LazyPluginCollection
* The block's plugin collection.
*/
protected function getPluginCollection() {
if (!$this->pluginCollection) {
$this->pluginCollection = new BlockPluginCollection(\Drupal::service('plugin.manager.block'), $this->plugin, $this
->get('settings'), $this
->id());
}
return $this->pluginCollection;
}
/**
* {@inheritdoc}
*/
public function getPluginCollections() {
return [
'settings' => $this
->getPluginCollection(),
'visibility' => $this
->getVisibilityConditions(),
];
}
/**
* {@inheritdoc}
*/
public function getPluginId() {
return $this->plugin;
}
/**
* {@inheritdoc}
*/
public function getRegion() {
return $this->region;
}
/**
* {@inheritdoc}
*/
public function getTheme() {
return $this->theme;
}
/**
* {@inheritdoc}
*/
public function getWeight() {
return $this->weight;
}
/**
* {@inheritdoc}
*/
public function label() {
$settings = $this
->get('settings');
if ($settings['label']) {
return $settings['label'];
}
else {
$definition = $this
->getPlugin()
->getPluginDefinition();
return $definition['admin_label'];
}
}
/**
* Sorts active blocks by weight; sorts inactive blocks by name.
*/
public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
// Separate enabled from disabled.
$status = (int) $b
->status() - (int) $a
->status();
if ($status !== 0) {
return $status;
}
// Sort by weight, unless disabled.
if ($a
->getRegion() != static::BLOCK_REGION_NONE) {
$weight = $a
->getWeight() - $b
->getWeight();
if ($weight) {
return $weight;
}
}
// Sort by label.
return strcmp($a
->label(), $b
->label());
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
parent::calculateDependencies();
$this
->addDependency('theme', $this->theme);
return $this;
}
/**
* {@inheritdoc}
*/
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
// Entity::postSave() calls Entity::invalidateTagsOnSave(), which only
// handles the regular cases. The Block entity has one special case: a
// newly created block may *also* appear on any page in the current theme,
// so we must invalidate the associated block's cache tag (which includes
// the theme cache tag).
if (!$update) {
Cache::invalidateTags($this
->getCacheTagsToInvalidate());
}
}
/**
* {@inheritdoc}
*/
public function getVisibility() {
return $this
->getVisibilityConditions()
->getConfiguration();
}
/**
* {@inheritdoc}
*/
public function setVisibilityConfig($instance_id, array $configuration) {
$conditions = $this
->getVisibilityConditions();
if (!$conditions
->has($instance_id)) {
$configuration['id'] = $instance_id;
$conditions
->addInstanceId($instance_id, $configuration);
}
else {
$conditions
->setInstanceConfiguration($instance_id, $configuration);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function getVisibilityConditions() {
if (!isset($this->visibilityCollection)) {
$this->visibilityCollection = new ConditionPluginCollection($this
->conditionPluginManager(), $this
->get('visibility'));
}
return $this->visibilityCollection;
}
/**
* {@inheritdoc}
*/
public function getVisibilityCondition($instance_id) {
return $this
->getVisibilityConditions()
->get($instance_id);
}
/**
* Gets the condition plugin manager.
*
* @return \Drupal\Core\Executable\ExecutableManagerInterface
* The condition plugin manager.
*/
protected function conditionPluginManager() {
$this->conditionPluginManager;
if (!isset($this->conditionPluginManager)) {
$this->conditionPluginManager = \Drupal::service('plugin.manager.condition');
}
return $this->conditionPluginManager;
}
/**
* {@inheritdoc}
*/
public function setRegion($region) {
$this->region = $region;
return $this;
}
/**
* {@inheritdoc}
*/
public function setWeight($weight) {
$this->weight = $weight;
return $this;
}
/**
* {@inheritdoc}
*/
public function createDuplicateBlock($new_id = NULL, $new_theme = NULL) {
$duplicate = parent::createDuplicate();
if (!empty($new_id)) {
$duplicate->id = $new_id;
}
if (!empty($new_theme)) {
$duplicate->theme = $new_theme;
}
return $duplicate;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Block:: |
protected | property | The condition plugin manager. | |
Block:: |
protected | property | The available contexts for this block and its visibility conditions. | |
Block:: |
protected | property | The ID of the block. | |
Block:: |
protected | property | The plugin instance ID. | |
Block:: |
protected | property | The plugin collection that holds the block plugin for this entity. | |
Block:: |
protected | property | The region this block is placed in. | |
Block:: |
protected | property | The plugin instance settings. | |
Block:: |
protected | property | The theme that includes the block plugin for this entity. | |
Block:: |
protected | property | The visibility settings for this block. | |
Block:: |
protected | property | The visibility collection. | |
Block:: |
protected | property | The block weight. | |
Block:: |
public | function |
Calculates dependencies and stores them in the dependency property. Overrides ConfigEntityBase:: |
|
Block:: |
protected | function | Gets the condition plugin manager. | |
Block:: |
public | function |
Creates a duplicate of the block entity. Overrides BlockInterface:: |
|
Block:: |
public | function |
Returns the plugin instance. Overrides BlockInterface:: |
|
Block:: |
protected | function | Encapsulates the creation of the block's LazyPluginCollection. | |
Block:: |
public | function |
Gets the plugin collections used by this entity. Overrides EntityWithPluginCollectionInterface:: |
|
Block:: |
public | function |
Returns the plugin ID. Overrides BlockInterface:: |
|
Block:: |
public | function |
Returns the region this block is placed in. Overrides BlockInterface:: |
|
Block:: |
public | function |
Returns the theme ID. Overrides BlockInterface:: |
|
Block:: |
public | function |
Returns an array of visibility condition configurations. Overrides BlockInterface:: |
|
Block:: |
public | function |
Gets a visibility condition plugin instance. Overrides BlockInterface:: |
|
Block:: |
public | function |
Gets conditions for this block. Overrides BlockInterface:: |
|
Block:: |
public | function |
Returns the weight of this block (used for sorting). Overrides BlockInterface:: |
|
Block:: |
public | function |
Gets the label of the entity. Overrides Entity:: |
|
Block:: |
public | function |
Acts on a saved entity before the insert or update hook is invoked. Overrides Entity:: |
|
Block:: |
public | function |
Sets the region this block is placed in. Overrides BlockInterface:: |
|
Block:: |
public | function |
Sets the visibility condition configuration. Overrides BlockInterface:: |
|
Block:: |
public | function |
Sets the block weight. Overrides BlockInterface:: |
|
Block:: |
public static | function |
Sorts active blocks by weight; sorts inactive blocks by name. Overrides ConfigEntityBase:: |
|
BlockInterface:: |
constant | Indicates the block label (title) should be displayed to end users. | ||
BlockInterface:: |
constant | Denotes that a block is not enabled in any region and should not be shown. | ||
ConfigEntityBase:: |
private | property | Whether the config is being created, updated or deleted through the import process. | |
ConfigEntityBase:: |
private | property | Whether the config is being deleted by the uninstall process. | |
ConfigEntityBase:: |
protected | property | The language code of the entity's default language. | |
ConfigEntityBase:: |
protected | property | The original ID of the configuration entity. | |
ConfigEntityBase:: |
protected | property | The name of the property that is used to store plugin configuration. | |
ConfigEntityBase:: |
protected | property | The enabled/disabled status of the configuration entity. | 2 |
ConfigEntityBase:: |
protected | property | Third party entity settings. | |
ConfigEntityBase:: |
protected | property | Trust supplied data and not use configuration schema on save. | |
ConfigEntityBase:: |
protected | property | The UUID for this entity. | |
ConfigEntityBase:: |
protected | function | Overrides \Drupal\Core\Entity\DependencyTrait:addDependency(). | |
ConfigEntityBase:: |
public | function |
Creates a duplicate of the entity. Overrides Entity:: |
1 |
ConfigEntityBase:: |
public | function |
Disables the configuration entity. Overrides ConfigEntityInterface:: |
1 |
ConfigEntityBase:: |
public | function |
Enables the configuration entity. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Returns the value of a property. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Returns the cache tags that should be used to invalidate caches. Overrides Entity:: |
1 |
ConfigEntityBase:: |
public | function |
Gets the configuration dependency name. Overrides Entity:: |
|
ConfigEntityBase:: |
protected static | function | Gets the configuration manager. | |
ConfigEntityBase:: |
public | function |
Gets the configuration target identifier for the entity. Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Gets the configuration dependencies. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Gets the original ID. Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Gets the list of third parties that store information. Overrides ThirdPartySettingsInterface:: |
|
ConfigEntityBase:: |
public | function |
Gets the value of a third-party setting. Overrides ThirdPartySettingsInterface:: |
|
ConfigEntityBase:: |
public | function |
Gets all third-party settings of a given module. Overrides ThirdPartySettingsInterface:: |
|
ConfigEntityBase:: |
protected | function | Gets the typed config manager. | |
ConfigEntityBase:: |
public | function |
Gets whether on not the data is trusted. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
protected static | function |
Override to never invalidate the individual entities' cache tags; the
config system already invalidates them. Overrides Entity:: |
|
ConfigEntityBase:: |
protected | function |
Override to never invalidate the entity's cache tag; the config system
already invalidates it. Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Checks whether this entity is installable. Overrides ConfigEntityInterface:: |
2 |
ConfigEntityBase:: |
public | function |
Overrides Entity::isNew(). Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Returns whether this entity is being changed as part of an import process. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Returns whether this entity is being changed during the uninstall process. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Deprecated way of generating a link to the entity. See toLink(). Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Informs the entity that entities it depends on will be deleted. Overrides ConfigEntityInterface:: |
4 |
ConfigEntityBase:: |
public static | function |
Acts on entities before they are deleted and before hooks are invoked. Overrides Entity:: |
7 |
ConfigEntityBase:: |
public | function |
Acts on an entity before the presave hook is invoked. Overrides Entity:: |
12 |
ConfigEntityBase:: |
public | function |
Saves an entity permanently. Overrides Entity:: |
1 |
ConfigEntityBase:: |
public | function |
Sets the value of a property. Overrides ConfigEntityInterface:: |
1 |
ConfigEntityBase:: |
public | function |
Sets the original ID. Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Sets the status of the configuration entity. Overrides ConfigEntityInterface:: |
1 |
ConfigEntityBase:: |
public | function |
Sets the status of the isSyncing flag. Overrides ConfigEntityInterface:: |
|
ConfigEntityBase:: |
public | function |
Sets the value of a third-party setting. Overrides ThirdPartySettingsInterface:: |
|
ConfigEntityBase:: |
public | function | ||
ConfigEntityBase:: |
public | function |
Returns whether the configuration entity is enabled. Overrides ConfigEntityInterface:: |
2 |
ConfigEntityBase:: |
public | function |
Gets an array of all property values. Overrides Entity:: |
2 |
ConfigEntityBase:: |
public | function |
Gets the URL object for the entity. Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Sets that the data should be trusted. Overrides ConfigEntityInterface:: |
1 |
ConfigEntityBase:: |
public | function |
Unsets a third-party setting. Overrides ThirdPartySettingsInterface:: |
|
ConfigEntityBase:: |
public | function |
Gets the public URL for this entity. Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Gets the URL object for the entity. Overrides Entity:: |
|
ConfigEntityBase:: |
public | function |
Constructs an Entity object. Overrides Entity:: |
10 |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | Aliased as: traitSleep | 1 |
DependencySerializationTrait:: |
public | function | 2 | |
DependencyTrait:: |
protected | property | The object's dependencies. | 1 |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. Aliased as: addDependencyTrait | |
Entity:: |
protected | property | Boolean indicating whether the entity should be forced to be new. | |
Entity:: |
protected | property | The entity type. | |
Entity:: |
protected | property | A typed data object wrapping this entity. | |
Entity:: |
public | function |
Checks data value access. Overrides AccessibleInterface:: |
1 |
Entity:: |
public | function |
Gets the bundle of the entity. Overrides EntityInterface:: |
1 |
Entity:: |
public static | function |
Overrides EntityInterface:: |
|
Entity:: |
public | function |
Deletes an entity permanently. Overrides EntityInterface:: |
2 |
Entity:: |
public | function |
Enforces an entity to be new. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Gets the entity manager. | |
Entity:: |
protected | function | Gets the entity type manager. | |
Entity:: |
public | function |
The cache contexts associated with this object. Overrides RefinableCacheableDependencyTrait:: |
|
Entity:: |
public | function |
The maximum age for which this object may be cached. Overrides RefinableCacheableDependencyTrait:: |
|
Entity:: |
public | function |
The cache tags associated with this object. Overrides RefinableCacheableDependencyTrait:: |
|
Entity:: |
public | function |
Gets the key that is used to store configuration dependencies. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the entity type definition. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the ID of the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets a typed data object for this entity object. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Indicates if a link template exists for a given key. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the identifier. Overrides EntityInterface:: |
11 |
Entity:: |
public | function |
Gets the language of the entity. Overrides EntityInterface:: |
1 |
Entity:: |
protected | function | Gets the language manager. | |
Entity:: |
protected | function | Gets an array link templates. | 1 |
Entity:: |
public static | function |
Overrides EntityInterface:: |
|
Entity:: |
public static | function |
Overrides EntityInterface:: |
|
Entity:: |
public | function |
Acts on an entity after it is created but before hooks are invoked. Overrides EntityInterface:: |
4 |
Entity:: |
public static | function |
Acts on deleted entities before the delete hook is invoked. Overrides EntityInterface:: |
14 |
Entity:: |
public static | function |
Acts on loaded entities. Overrides EntityInterface:: |
2 |
Entity:: |
public static | function |
Changes the values of an entity before it is created. Overrides EntityInterface:: |
6 |
Entity:: |
public | function |
Gets a list of entities referenced by this entity. Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Generates the HTML for a link to this entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns a list of URI relationships supported by this entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Gets an array of placeholders for this entity. | 1 |
Entity:: |
public | function |
Gets the entity UUID (Universally Unique Identifier). Overrides EntityInterface:: |
1 |
Entity:: |
protected | function | Gets the UUID generator. | |
Entity:: |
public | function | 5 | |
PluginDependencyTrait:: |
protected | function | Calculates and adds dependencies of a specific plugin instance. | 1 |
RefinableCacheableDependencyTrait:: |
protected | property | Cache contexts. | |
RefinableCacheableDependencyTrait:: |
protected | property | Cache max-age. | |
RefinableCacheableDependencyTrait:: |
protected | property | Cache tags. | |
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function |