You are here

class BundleField in Display Suite 8.4

Same name in this branch
  1. 8.4 src/Plugin/Derivative/BundleField.php \Drupal\ds\Plugin\Derivative\BundleField
  2. 8.4 src/Plugin/DsField/BundleField.php \Drupal\ds\Plugin\DsField\BundleField
Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/BundleField.php \Drupal\ds\Plugin\Derivative\BundleField
  2. 8.3 src/Plugin/Derivative/BundleField.php \Drupal\ds\Plugin\Derivative\BundleField

Provides a derivative for bundle fields.

Hierarchy

Expanded class hierarchy of BundleField

File

src/Plugin/Derivative/BundleField.php, line 13

Namespace

Drupal\ds\Plugin\Derivative
View source
class BundleField extends DeriverBase implements ContainerDeriverInterface {

  /**
   * Stores all entity row plugin information.
   *
   * @var array
   */
  protected $derivatives = [];

  /**
   * The base plugin ID that the derivative is for.
   *
   * @var string
   */
  protected $basePluginId;

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

  /**
   * Constructs a DsEntityRow object.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity manager.
   */
  public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) {
    $this->basePluginId = $base_plugin_id;
    $this->entityTypeManager = $entity_type_manager;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {
      $base_table = $entity_type
        ->getBaseTable();
      if ($entity_type
        ->get('field_ui_base_route') && !empty($base_table)) {
        $this->derivatives[$entity_type_id] = $base_plugin_definition;
        $this->derivatives[$entity_type_id] += [
          'provider' => $entity_type_id,
          'title' => 'Bundle name',
          'entity_type' => $entity_type_id,
        ];
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BundleField::$basePluginId protected property The base plugin ID that the derivative is for.
BundleField::$derivatives protected property Stores all entity row plugin information. Overrides DeriverBase::$derivatives
BundleField::$entityTypeManager protected property The entity manager.
BundleField::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
BundleField::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
BundleField::__construct public function Constructs a DsEntityRow object.
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition