Skip to content
Snippets Groups Projects
Commit aaa5bf5e authored by Marc van Gend's avatar Marc van Gend
Browse files

move the getBlockList method to the deriver class

parent 2d87c121
No related branches found
No related tags found
No related merge requests found
......@@ -2,50 +2,7 @@
namespace Drupal\fieldblock;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class FieldBlockHelper {
use StringTranslationTrait;
/**
* Builds a list of fields that have been made available as a block.
*
* @return array An array of fieldblocks.
*
* @todo decide if this function should go into the fieldblock deriver class.
*/
public static function fieldBlockGetBlockList() {
$fieldblocks = &drupal_static(__FUNCTION__);
if (!isset($fieldblocks)) {
$fieldblocks = array();
$entity_view_displays = EntityViewDisplay::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] = t('@field field (from @type: @bundle: @mode)', array(
'@field' => $field_label,
'@type' => $entity_type,
'@bundle' => $bundle,
'@mode' => $mode,
));
}
}
}
return $fieldblocks;
}
}
......@@ -9,6 +9,8 @@ namespace Drupal\fieldblock\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\fieldblock\FieldBlockHelper;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Provides block plugin definitions for fieldblock blocks.
......@@ -16,6 +18,9 @@ use Drupal\fieldblock\FieldBlockHelper;
* @see \Drupal\fieldblock\Plugin\Block\FieldBlock
*/
class FieldBlock extends DeriverBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
......@@ -29,4 +34,40 @@ class FieldBlock extends DeriverBase {
return $this->derivatives;
}
/**
* Builds a list of fields that have been made available as a block.
*
* @return array An array of fieldblocks.
*/
public static function fieldBlockGetBlockList() {
$fieldblocks = &drupal_static(__FUNCTION__);
if (!isset($fieldblocks)) {
$fieldblocks = array();
// Get all EntityViewDisplay config entities and iterate over them.
$entity_view_displays = EntityViewDisplay::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] = t('@field field (from @type: @bundle: @mode)', array(
'@field' => $field_label,
'@type' => $entity_type,
'@bundle' => $bundle,
'@mode' => $mode,
));
}
}
}
return $fieldblocks;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment