class ParagraphBlocksDeriver in Paragraph blocks 8
Same name and namespace in other branches
- 8.2 src/Plugin/Deriver/ParagraphBlocksDeriver.php \Drupal\paragraph_blocks\Plugin\Deriver\ParagraphBlocksDeriver
 - 3.x src/Plugin/Deriver/ParagraphBlocksDeriver.php \Drupal\paragraph_blocks\Plugin\Deriver\ParagraphBlocksDeriver
 
Provides entity field block definitions for every field.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\ctools\Plugin\Deriver\EntityDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
- class \Drupal\paragraph_blocks\Plugin\Deriver\ParagraphBlocksDeriver
 
 
 - class \Drupal\ctools\Plugin\Deriver\EntityDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
 
Expanded class hierarchy of ParagraphBlocksDeriver
File
- src/
Plugin/ Deriver/ ParagraphBlocksDeriver.php, line 11  
Namespace
Drupal\paragraph_blocks\Plugin\DeriverView source
class ParagraphBlocksDeriver extends EntityDeriverBase {
  // @todo: make this configuration
  const MAX_CARDINALITY = 50;
  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $entity_type_labels = $this->entityManager
      ->getEntityTypeLabels();
    foreach ($this->entityManager
      ->getFieldMap() as $entity_type_id => $field_info) {
      if ($entity_type_id == 'paragraph') {
        continue;
      }
      /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage_definition */
      foreach ($this->entityManager
        ->getFieldStorageDefinitions($entity_type_id) as $field_storage_definition) {
        $field_name = $field_storage_definition
          ->getName();
        $field_storage_type = $field_storage_definition
          ->getType();
        if ($field_storage_definition
          ->getType() != 'entity_reference_revisions' || $field_storage_definition
          ->getSettings()['target_type'] != 'paragraph') {
          continue;
        }
        // Get the field's label.
        $first_bundle = reset($field_info[$field_name]['bundles']);
        $bundle_field_definitions = $this->entityManager
          ->getFieldDefinitions($entity_type_id, $first_bundle);
        $admin_label = $bundle_field_definitions[$field_name]
          ->getLabel();
        // Create a plugin of maximum number of cardinality this field allows.
        // Unavailable items are removed in hook_panels_ipe_blocks_alter().
        // Labels are overridden in hook_panels_ipe_blocks_alter().
        $cardinality = $field_storage_definition
          ->getCardinality();
        if ($cardinality == 1) {
          // Skip fields with cardinality one. This can be handled as a field.
          continue;
        }
        if ($cardinality === -1) {
          $cardinality = ParagraphBlocksDeriver::MAX_CARDINALITY;
        }
        for ($delta = 0; $delta < $cardinality; $delta++) {
          $plugin_id = "{$entity_type_id}:{$field_name}:{$delta}";
          $this->derivatives[$plugin_id] = [
            'context' => [
              'entity' => new ContextDefinition('entity:' . $entity_type_id, $entity_type_labels[$entity_type_id], TRUE),
            ],
          ] + $base_plugin_definition;
        }
      }
    }
    return $this->derivatives;
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            DeriverBase:: | 
                  protected | property | List of derivative definitions. | 1 | 
| 
            DeriverBase:: | 
                  public | function | 
            Gets the definition of a derivative plugin. Overrides DeriverInterface:: | 
                  |
| 
            EntityDeriverBase:: | 
                  protected | property | The entity field manager. | |
| 
            EntityDeriverBase:: | 
                  protected | property | The entity type manager. | |
| 
            EntityDeriverBase:: | 
                  protected | property | The entity type repository. | |
| 
            EntityDeriverBase:: | 
                  public static | function | 
            Creates a new class instance. Overrides ContainerDeriverInterface:: | 
                  |
| 
            EntityDeriverBase:: | 
                  public | function | Constructs new EntityViewDeriver. | |
| 
            ParagraphBlocksDeriver:: | 
                  public | function | 
            Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: | 
                  |
| 
            ParagraphBlocksDeriver:: | 
                  constant | |||
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            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. |