DynamicField.php in Display Suite 8.2
File
src/Plugin/Derivative/DynamicField.php
View source
<?php
namespace Drupal\ds\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Component\Utility\Html;
abstract class DynamicField extends DeriverBase {
public function getDerivativeDefinitions($base_plugin_definition) {
$custom_fields = \Drupal::configFactory()
->listAll('ds.field.');
foreach ($custom_fields as $config) {
$field = \Drupal::config($config)
->get();
if ($field['type'] == $this
->getType()) {
foreach ($field['entities'] as $entity_type) {
$key = $this
->getKey($entity_type, $field);
$this->derivatives[$key] = $base_plugin_definition;
$this->derivatives[$key] += array(
'title' => \Drupal::translation()
->translate(Html::escape($field['label'])),
'properties' => $field['properties'],
'entity_type' => $entity_type,
);
if (!empty($field['ui_limit'])) {
$this->derivatives[$key]['ui_limit'] = explode("\n", $field['ui_limit']);
foreach ($this->derivatives[$key]['ui_limit'] as $k => $v) {
$this->derivatives[$key]['ui_limit'][$k] = trim($v);
}
}
}
}
}
return $this->derivatives;
}
protected function getType() {
return '';
}
protected function getKey($entity_type, $field) {
return $entity_type . '-' . $field['id'];
}
}