protected function ViewsFieldFormatter::getArguments in Views field formatter 8
Helper function. Returns the arguments to send to the views.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The items.
mixed $item: The current item.
mixed $delta: The item delta.
Return value
array The arguments array.
1 call to ViewsFieldFormatter::getArguments()
- ViewsFieldFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ ViewsFieldFormatter.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ ViewsFieldFormatter.php, line 333
Class
- ViewsFieldFormatter
- Class ViewsFieldFormatter.
Namespace
Drupal\views_field_formatter\Plugin\Field\FieldFormatterCode
protected function getArguments(FieldItemListInterface $items, $item, $delta) {
$settings = $this
->getSettings();
$user_arguments = \array_keys(\array_filter($settings['arguments'], static function ($argument) {
return $argument['checked'];
}));
$arguments = [];
foreach ($user_arguments as $argument) {
switch ($argument) {
case 'field_value':
$columns = \array_keys($items
->getFieldDefinition()
->getFieldStorageDefinition()
->getSchema()['columns']);
$column = \array_shift($columns);
$cardinality = $items
->getFieldDefinition()
->getFieldStorageDefinition()
->getCardinality();
/** @var FieldItemInterface $item */
if ($item) {
$arguments[$argument] = !empty($column) && isset($item
->getValue()[$column]) ? $item
->getValue()[$column] : NULL;
}
if ((bool) $settings['multiple'] === TRUE && $cardinality !== 1) {
if (!empty($settings['implode_character'])) {
$values = [];
/** @var FieldItemInterface $item */
foreach ($items as $item) {
$values[] = !empty($column) && isset($item
->getValue()[$column]) ? $item
->getValue()[$column] : NULL;
}
if (!empty($values)) {
$arguments[$argument] = \implode($settings['implode_character'], \array_filter($values));
}
}
}
break;
case 'entity_id':
$arguments[$argument] = $items
->getParent()
->getValue()
->id();
break;
case 'entity_revision_id':
$arguments[$argument] = $items
->getParent()
->getValue()
->getRevisionId();
break;
case 'delta':
$arguments[$argument] = isset($delta) ? $delta : NULL;
break;
}
}
return \array_values($arguments);
}