protected function ViewsFieldTemplate::setConfigurableFieldsDerivatives in Calendar 8
Set all derivatives for an entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type service.
array $base_plugin_definition: The array.
1 call to ViewsFieldTemplate::setConfigurableFieldsDerivatives()
- ViewsFieldTemplate::getDerivativeDefinitions in src/
Plugin/ Derivative/ ViewsFieldTemplate.php - Gets the definition of all derivatives of a base plugin.
File
- src/
Plugin/ Derivative/ ViewsFieldTemplate.php, line 145
Class
- ViewsFieldTemplate
- Derivative class to find all field and properties for calendar View Builders.
Namespace
Drupal\calendar\Plugin\DerivativeCode
protected function setConfigurableFieldsDerivatives(EntityTypeInterface $entity_type, array $base_plugin_definition) {
/** @var \Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage */
$field_storages = $this->fieldManager
->getFieldStorageDefinitions($entity_type
->id());
foreach ($field_storages as $field_id => $field_storage) {
$type = $field_storage
->getType();
$field_definition = \Drupal::service('plugin.manager.field.field_type')
->getDefinition($type);
$class = $field_definition['class'];
$classes = [];
$classes[$type] = [];
$classes[$type][] = $class;
while ($class !== FALSE) {
$classes[$type][] = get_parent_class($class);
$class = end($classes[$type]);
}
if (in_array("Drupal\\datetime\\Plugin\\Field\\FieldType\\DateTimeItem", $classes[$type])) {
$entity_type_id = $entity_type
->id();
$views_data = $this->viewsData
->getAll();
foreach ($views_data as $key => $data) {
if (strstr($key, $field_id) && isset($data[$field_id])) {
$field_table = $key;
$field_table_data = $data;
break;
}
}
if (isset($field_table_data)) {
$derivative = [];
$field_info = $field_table_data[$field_id];
$derivative['field_id'] = $field_id;
$join_tables = array_keys($field_table_data['table']['join']);
// @todo Will there ever be more than 1 tables here?
$join_table = array_pop($join_tables);
$join_table_data = $this->viewsData
->get($join_table);
$derivative = [
'replacements' => [
'field_id' => $field_id,
'entity_type' => $entity_type_id,
'entity_label' => $entity_type
->getLabel(),
'field_label' => $field_info['title'],
'base_table' => $join_table,
'field_table' => $field_table,
'default_field_id' => $this
->getTableDefaultField($join_table_data, $entity_type_id),
'base_field' => $this
->getTableBaseField($join_table_data),
],
'view_template_id' => 'calendar_config_field',
];
$this
->setDerivative($derivative, $base_plugin_definition);
// $this->setDerivative($field_info, $entity_type, $field_table_data, $base_plugin_definition);
}
}
}
}