class FieldBlock in Field as Block 8
Same name in this branch
- 8 src/Plugin/Derivative/FieldBlock.php \Drupal\fieldblock\Plugin\Derivative\FieldBlock
- 8 src/Plugin/Block/FieldBlock.php \Drupal\fieldblock\Plugin\Block\FieldBlock
Provides block plugin definitions for fieldblock blocks.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\fieldblock\Plugin\Derivative\FieldBlock implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of FieldBlock
See also
\Drupal\fieldblock\Plugin\Block\FieldBlock
File
- src/
Plugin/ Derivative/ FieldBlock.php, line 22 - Contains \Drupal\fieldblock\Plugin\Derivative\FieldBlock.
Namespace
Drupal\fieldblock\Plugin\DerivativeView source
class FieldBlock extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* The entity view display storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $entityViewDisplayStorage;
/**
* Constructs a FieldBlock deriver object.
*
* @param \Drupal\Core\Entity\Entity\EntityViewDisplay $entity_view_display
* The entity view display storage.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation.
*/
public function __construct($entity_view_display, TranslationInterface $string_translation) {
$this->entityViewDisplayStorage = $entity_view_display;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
/** @var EntityManagerInterface $entity_manager */
$entity_manager = $container
->get('entity.manager');
return new static($entity_manager
->getStorage('entity_view_display'), $container
->get('string_translation'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$blocks = $this
->fieldBlockGetBlockList();
foreach ($blocks as $fieldblock_id => $description) {
$this->derivatives[$fieldblock_id] = $base_plugin_definition;
$this->derivatives[$fieldblock_id]['admin_label'] = $description;
}
return $this->derivatives;
}
/**
* Builds a list of fields that have been made available as a block.
*
* @return string[]
* An array of fieldblocks in the form of fieldblock_id => admin label.
*/
protected function fieldBlockGetBlockList() {
$fieldblocks = array();
// Get all EntityViewDisplay config entities and iterate over them.
$entity_view_displays = $this->entityViewDisplayStorage
->loadMultiple();
/** @var \Drupal\Core\Entity\EntityDisplayModeInterface $entity_view_display */
foreach ($entity_view_displays as $display_id => $entity_view_display) {
$view_display_fieldblocks = $entity_view_display
->getThirdPartySettings('fieldblock');
$entity_type = $entity_view_display
->get('targetEntityType');
$bundle = $entity_view_display
->get('bundle');
$mode = $entity_view_display
->get('mode');
foreach ($view_display_fieldblocks as $field_name => $field_label) {
$fieldblock_id = $display_id . ':' . $field_name;
$fieldblocks[$fieldblock_id] = $this
->t('@field field (from @type: @bundle: @mode)', array(
'@field' => $field_label,
'@type' => $entity_type,
'@bundle' => $bundle,
'@mode' => $mode,
));
}
}
return $fieldblocks;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
FieldBlock:: |
protected | property | The entity view display storage. | |
FieldBlock:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
FieldBlock:: |
protected | function | Builds a list of fields that have been made available as a block. | |
FieldBlock:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
FieldBlock:: |
public | function | Constructs a FieldBlock deriver object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |