You are here

class FormEntityProfileTypeDeriver in Flexiform 8

Provides a deriver class.

Hierarchy

Expanded class hierarchy of FormEntityProfileTypeDeriver

File

src/Plugin/Deriver/FormEntityProfileTypeDeriver.php, line 17

Namespace

Drupal\flexiform\Plugin\Deriver
View source
class FormEntityProfileTypeDeriver extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The entity bundle info manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
   */
  protected $entityBundleInfo;

  /**
   * Constructs new EntityViewDeriver.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity manager.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translation service.
   * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_bundle_info
   *   The entity bundle info service.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager, TranslationInterface $string_translation, EntityTypeBundleInfoInterface $entity_bundle_info) {
    $this->entityBundleInfo = $entity_bundle_info;
    $this->entityTypeManager = $entity_manager;
    $this->stringTranslation = $string_translation;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    if (!\Drupal::moduleHandler()
      ->moduleExists('profile')) {
      return [];
    }
    $entity_type = $this->entityTypeManager
      ->getDefinition('profile');
    foreach ($this->entityBundleInfo
      ->getBundleInfo('profile') as $bundle => $bundle_info) {
      $plugin_id = $bundle;
      $this->derivatives[$plugin_id] = [
        'label' => $this
          ->t('@bundle @profile from User', [
          '@bundle' => $bundle_info['label'],
          '@profile' => $entity_type
            ->getLabel(),
        ]),
        'profile_type' => $bundle,
        'context' => [
          'user' => new ContextDefinition('entity:user', $this
            ->t('Base User')),
        ],
      ] + $base_plugin_definition;
    }
    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
FormEntityProfileTypeDeriver::$entityBundleInfo protected property The entity bundle info manager.
FormEntityProfileTypeDeriver::$entityTypeManager protected property The entity manager.
FormEntityProfileTypeDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
FormEntityProfileTypeDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
FormEntityProfileTypeDeriver::__construct public function Constructs new EntityViewDeriver.
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.