You are here

protected function FieldBlock::fieldBlockGetBlockList in Field as Block 8

Builds a list of fields that have been made available as a block.

Return value

string[] An array of fieldblocks in the form of fieldblock_id => admin label.

1 call to FieldBlock::fieldBlockGetBlockList()
FieldBlock::getDerivativeDefinitions in src/Plugin/Derivative/FieldBlock.php
Gets the definition of all derivatives of a base plugin.

File

src/Plugin/Derivative/FieldBlock.php, line 78
Contains \Drupal\fieldblock\Plugin\Derivative\FieldBlock.

Class

FieldBlock
Provides block plugin definitions for fieldblock blocks.

Namespace

Drupal\fieldblock\Plugin\Derivative

Code

protected function fieldBlockGetBlockList() {
  $fieldblocks = array();

  // Get all EntityViewDisplay config entities and iterate over them.
  $entity_view_displays = $this->entityViewDisplayStorage
    ->loadMultiple();

  /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $entity_view_display */
  foreach ($entity_view_displays as $display_id => $entity_view_display) {
    $view_display_fieldblocks = $entity_view_display
      ->getThirdPartySettings('fieldblock');
    $entity_type = $entity_view_display
      ->get('targetEntityType');
    $bundle = $entity_view_display
      ->get('bundle');
    $mode = $entity_view_display
      ->get('mode');
    foreach ($view_display_fieldblocks as $field_name => $field_label) {
      $fieldblock_id = $display_id . ':' . $field_name;
      $fieldblocks[$fieldblock_id] = $this
        ->t('@field field (from @type: @bundle: @mode)', array(
        '@field' => $field_label,
        '@type' => $entity_type,
        '@bundle' => $bundle,
        '@mode' => $mode,
      ));
    }
  }
  return $fieldblocks;
}