FieldEmbedView::fieldRowSettingsForm()
contains the following code.
$elements['view_display'] = [
'#type' => 'select',
'#title' => t('Display'),
'#options' => $display_options,
'#default_value' => $default_display_id,
'#description' => t('The view display used for render.'),
'#weight' => 0,
];
$elements['enable_ajax'] = [
'#type' => 'checkbox',
'#title' => t('Force ajax enabled'),
'#default_value' => $display_settings['enable_ajax'] ?? FALSE,
'#weight' => 0,
];
// Omissis
$elements['arguments']['#tree'] = TRUE;
$elements['arguments']['#prefix'] = '<h4>' . t('Arguments:') . '</h4>';
// Omissis
if (!isset($elements['display_options']['arguments'])) {
// No argument found.
$elements['arguments']['message'] = [
'#markup' => t('No argument found on this display.'),
];
}
else {
foreach ($display['display_options']['arguments'] as $argument) {
$handler = $executable->display_handler->getHandler('argument', $argument['id']);
$field_name = $handler->adminLabel(TRUE);
if (!empty($argument['relationship']) && !empty($relationships[$argument['relationship']])) {
$field_name = '(' . $relationships[$argument['relationship']] . ') ' . $field_name;
}
$elements['arguments'][$argument['id']] = [
'#title' => $field_name,
'#type' => 'entity_field_select',
'#entity_type' => $this->getEntityTypeId(),
'#bundle' => $this->bundle(),
'#required' => FALSE,
'#default_value' => $display_settings['arguments'][$argument['id']] ?? NULL,
'#description' => t('You can set the arguments value from a field of this entity and those possible referenced entities.'),
];
}
}
Since $elements['display_options']['arguments']
(where $elements
is a local variable) is never set, the else
part will never be executed.
I gather the correct code is the following one, which first checks $display['display_options']['arguments']
has been set; if it has been set, it loops over its values.
if (!isset($display['display_options']['arguments'])) {
// No argument found.
$elements['arguments']['message'] = [
'#markup' => t('No argument found on this display.'),
];
}
else {
foreach ($display['display_options']['arguments'] as $argument) {
$handler = $executable->display_handler->getHandler('argument', $argument['id']);
$field_name = $handler->adminLabel(TRUE);
if (!empty($argument['relationship']) && !empty($relationships[$argument['relationship']])) {
$field_name = '(' . $relationships[$argument['relationship']] . ') ' . $field_name;
}
$elements['arguments'][$argument['id']] = [
'#title' => $field_name,
'#type' => 'entity_field_select',
'#entity_type' => $this->getEntityTypeId(),
'#bundle' => $this->bundle(),
'#required' => FALSE,
'#default_value' => $display_settings['arguments'][$argument['id']] ?? NULL,
'#description' => t('You can set the arguments value from a field of this entity and those possible referenced entities.'),
];
}
}