You are here

abstract class WebformOptionsCustomDeriverBase in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_options_custom/src/Plugin/Derivative/WebformOptionsCustomDeriverBase.php \Drupal\webform_options_custom\Plugin\Derivative\WebformOptionsCustomDeriverBase

Provides base class for webform custom options derivers.

Hierarchy

Expanded class hierarchy of WebformOptionsCustomDeriverBase

File

modules/webform_options_custom/src/Plugin/Derivative/WebformOptionsCustomDeriverBase.php, line 15

Namespace

Drupal\webform_options_custom\Plugin\Derivative
View source
abstract class WebformOptionsCustomDeriverBase extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;
  use WebformEntityStorageTrait;

  /**
   * The type of custom element (element or entity_reference).
   *
   * @var string
   */
  protected $type;

  /**
   * Constructs new WebformReusableCompositeDeriver.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   * The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('entity_type.manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $webform_options_custom_entities = $this
      ->getEntityStorage('webform_options_custom')
      ->loadMultiple();
    foreach ($webform_options_custom_entities as $webform_options_custom_entity) {
      if ($webform_options_custom_entity
        ->get($this->type)) {
        $this->derivatives[$webform_options_custom_entity
          ->id()] = $base_plugin_definition;
        $this->derivatives[$webform_options_custom_entity
          ->id()]['label'] = $webform_options_custom_entity
          ->label() . ($this->type === 'entity_reference' ? ' ' . $this
          ->t('(Entity reference)') : '');
        $this->derivatives[$webform_options_custom_entity
          ->id()]['description'] = $webform_options_custom_entity
          ->get('description');
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.
WebformEntityStorageTrait::$entityStorageToTypeMappings protected property An associate array of entity type storage aliases.
WebformEntityStorageTrait::$entityTypeManager protected property The entity type manager. 5
WebformEntityStorageTrait::getEntityStorage protected function Retrieves the entity storage.
WebformEntityStorageTrait::getSubmissionStorage protected function Retrieves the webform submission storage.
WebformEntityStorageTrait::getWebformStorage protected function Retrieves the webform storage.
WebformEntityStorageTrait::__get public function Implements the magic __get() method.
WebformOptionsCustomDeriverBase::$type protected property The type of custom element (element or entity_reference). 2
WebformOptionsCustomDeriverBase::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
WebformOptionsCustomDeriverBase::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
WebformOptionsCustomDeriverBase::__construct public function Constructs new WebformReusableCompositeDeriver.