protected function ViewsData::alterPluginFieldData in Plugin 8.2
Alters Views data for the "plugin" field type.
Parameters
array[] $data: An array of Views data.
\Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage_definition: The storage definition of the field to alter the data for.
string $table_name: The name of the table to alter the data for.
string $plugin_id_column_name: The name of the plugin ID column.
string|null $plugin_configuration_column_name: The name of the plugin configuration column, or NULL if there is none.
Throws
\InvalidArgumentException
2 calls to ViewsData::alterPluginFieldData()
- ViewsData::alterFieldViewsData in src/
ViewsData.php - Implements hook_field_views_data_alter().
- ViewsData::alterViewsData in src/
ViewsData.php - Implements hook_views_data_alter().
File
- src/
ViewsData.php, line 145
Class
- ViewsData
- Provides/alters Views data.
Namespace
Drupal\pluginCode
protected function alterPluginFieldData(array &$data, FieldStorageDefinitionInterface $field_storage_definition, $table_name, $plugin_id_column_name, $plugin_configuration_column_name = NULL) {
if (strpos($field_storage_definition
->getType(), 'plugin:')) {
throw new \InvalidArgumentException('The Views data being altered is not for a "plugin" field.');
}
// Do nothing if no Views data exists. This is the case for entity types
// without Views data handlers, for instance.
if (!isset($data[$table_name][$plugin_id_column_name])) {
return;
}
$plugin_type_id = substr($field_storage_definition
->getType(), 7);
$plugin_type = $this->pluginTypeManager
->getPluginType($plugin_type_id);
// Alter the plugin ID column.
/** @var \Drupal\Core\StringTranslation\TranslatableMarkup $plugin_id_old_title */
$plugin_id_old_title = $data[$table_name][$plugin_id_column_name]['title'];
$plugin_id_title_arguments = [
'@type_label' => $plugin_type
->getLabel(),
'@name' => $field_storage_definition
->getName(),
'@column' => $plugin_id_column_name,
];
$data[$table_name][$plugin_id_column_name]['title'] = new TranslatableMarkup('@type_label ID (@name:@column)', $plugin_id_title_arguments, $plugin_id_old_title
->getOptions());
$data[$table_name][$plugin_id_column_name]['filter']['id'] = 'plugin_id';
$data[$table_name][$plugin_id_column_name]['filter']['plugin_type_id'] = $plugin_type_id;
// Alter the plugin configuration column. We cannot display it, or filter by
// it, so we remove it to prevent confusion.
if ($plugin_configuration_column_name) {
unset($data[$table_name][$plugin_configuration_column_name]);
}
}