You are here

class EntityExtender in Rabbit Hole 8

Same name and namespace in other branches
  1. 2.x src/EntityExtender.php \Drupal\rabbit_hole\EntityExtender

Adds Rabbit Hole fields to supported entity types.

Hierarchy

Expanded class hierarchy of EntityExtender

1 string reference to 'EntityExtender'
rabbit_hole.services.yml in ./rabbit_hole.services.yml
rabbit_hole.services.yml
1 service uses EntityExtender
rabbit_hole.entity_extender in ./rabbit_hole.services.yml
Drupal\rabbit_hole\EntityExtender

File

src/EntityExtender.php, line 13

Namespace

Drupal\rabbit_hole
View 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

Namesort descending Modifiers Type Description Overrides
EntityExtender::$rhBehaviorPluginManager protected property Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginManager definition.
EntityExtender::$rhEntityPluginManager protected property Drupal\rabbit_hole\Plugin\RabbitHoleEntityPluginManager definition.
EntityExtender::getGeneralExtraFields public function Get the extra fields that should be applied to all rabbit hole entities. Overrides EntityExtenderInterface::getGeneralExtraFields
EntityExtender::getRabbitHoleFields public function Return fields added by rabbit hole for use in entity_base_field_info hooks.
EntityExtender::__construct public function Constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.