class EntityExtender in Rabbit Hole 2.x
Same name and namespace in other branches
- 8 src/EntityExtender.php \Drupal\rabbit_hole\EntityExtender
Adds Rabbit Hole fields to supported entity types.
Hierarchy
- class \Drupal\rabbit_hole\EntityExtender implements EntityExtenderInterface uses StringTranslationTrait
Expanded class hierarchy of EntityExtender
1 string reference to 'EntityExtender'
1 service uses EntityExtender
File
- src/
EntityExtender.php, line 13
Namespace
Drupal\rabbit_holeView source
class EntityExtender implements EntityExtenderInterface {
use StringTranslationTrait;
/**
* Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginManager definition.
*
* @var \Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginManager
*/
protected $rhBehaviorPluginManager;
/**
* Drupal\rabbit_hole\Plugin\RabbitHoleEntityPluginManager definition.
*
* @var \Drupal\rabbit_hole\Plugin\RabbitHoleEntityPluginManager
*/
protected $rhEntityPluginManager;
/**
* Constructor.
*/
public function __construct(RabbitHoleBehaviorPluginManager $plugin_manager_rabbit_hole_behavior_plugin, RabbitHoleEntityPluginManager $plugin_manager_rabbit_hole_entity_plugin) {
$this->rhBehaviorPluginManager = $plugin_manager_rabbit_hole_behavior_plugin;
$this->rhEntityPluginManager = $plugin_manager_rabbit_hole_entity_plugin;
}
/**
* Return fields added by rabbit hole for use in entity_base_field_info hooks.
*
* @param string $entity_type_id
* The string ID of the entity type.
*
* @return array
* An array of general extra fields.
*/
public function getRabbitHoleFields($entity_type_id) {
$entity_types = $this->rhEntityPluginManager
->loadSupportedEntityTypes();
if (in_array($entity_type_id, $entity_types)) {
return $this
->getGeneralExtraFields();
}
}
/**
* {@inheritdoc}
*/
public function getGeneralExtraFields() {
$fields = [];
$fields['rh_action'] = BaseFieldDefinition::create('string')
->setName('rh_action')
->setLabel($this
->t('Rabbit Hole action'))
->setDescription($this
->t('Specifies which action that Rabbit Hole should take.'));
foreach ($this->rhBehaviorPluginManager
->getDefinitions() as $id => $def) {
$this->rhBehaviorPluginManager
->createInstance($id)
->alterExtraFields($fields);
}
return $fields;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityExtender:: |
protected | property | Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginManager definition. | |
EntityExtender:: |
protected | property | Drupal\rabbit_hole\Plugin\RabbitHoleEntityPluginManager definition. | |
EntityExtender:: |
public | function |
Get the extra fields that should be applied to all rabbit hole entities. Overrides EntityExtenderInterface:: |
|
EntityExtender:: |
public | function | Return fields added by rabbit hole for use in entity_base_field_info hooks. | |
EntityExtender:: |
public | function | Constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |