Commit 09298184 authored by marcvangend's avatar marcvangend

move helper function to helper FieldBlockHelper

parent 9d4a3d9c
......@@ -5,7 +5,6 @@
* Allow fields to be rendered in blocks.
*/
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Form\FormStateInterface;
define('FIELDBLOCK_STORAGE_STATIC', 'fieldblock_storage');
......@@ -89,41 +88,6 @@ function fieldblock_field_display_submit($form, FormStateInterface $form_state)
* An array with all fields that are made visible via the display fields UI,
* in the form of [fieldblock identifier] => [block description].
*/
function fieldblock_get_block_list() {
$fieldblocks = &drupal_static(__FUNCTION__);
if (!isset($fieldblocks)) {
/** @var \Drupal\Core\Entity\EntityDisplayModeInterface $view_mode_config */
$entity_view_displays = EntityViewDisplay::loadMultiple();
foreach ($entity_view_displays as $name => $entity_view_display) {
// ToDo: This is not cool, I want a way to get all thirdpartysettings at once!
$fieldblock_settings = $entity_view_display->getThirdPartySetting('fieldblock');
}
$fieldblocks = array();
$config_names = \Drupal::configFactory()->listAll('fieldblock.');
foreach ($config_names as $config_name) {
$bundle_config = \Drupal::config($config_name)->get();
foreach ($bundle_config as $mode => $fields) {
foreach ($fields as $field_name => $field_label) {
list( , $entity_type, $bundle) = explode('.', $config_name);
$fieldblock_id = implode('_', array($entity_type, $bundle, $mode, $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;
}
///**
// * Implements hook_block_view().
......
<?php
namespace Drupal\fieldblock;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
class FieldBlockHelper {
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 = implode('_', array($entity_type, $bundle, $mode, $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;
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\fieldblock\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\fieldblock\FieldBlockHelper;
/**
* Provides block plugin definitions for fieldblock blocks.
......@@ -19,7 +20,7 @@ class FieldBlock extends DeriverBase {
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$blocks = fieldblock_get_block_list();
$blocks = FieldBlockHelper::fieldBlockGetBlockList();
foreach ($blocks as $fieldblock_id => $description) {
$this->derivatives[$fieldblock_id] = $base_plugin_definition;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment