Skip to content
Snippets Groups Projects
Commit d56042ce authored by Sean Blommaert's avatar Sean Blommaert Committed by Sean Blommaert
Browse files

Issue #2957177 by seanB, bgilhome, gambry, roborew, robin.ingelbrecht: Pass...

Issue #2957177 by seanB, bgilhome, gambry, roborew, robin.ingelbrecht: Pass view name and display id to alterFormField() method in ViewsReferenceSetting plugin
parent 709c1ccf
No related branches found
Tags 7.x-1.0-rc3
No related merge requests found
......@@ -88,25 +88,23 @@ trait ViewsReferenceTrait {
],
];
$default_value = isset($field_value['display_id']) ? $field_value['display_id'] : '';
$display_id = $field_value['display_id'] ?? NULL;
$view_name = $field_value['target_id'] ?? NULL;
$options = [];
if (!empty($field_value['target_id'])) {
if ($view_name) {
// Extract the view id from the text.
$full_view_name = $field_value['target_id'];
preg_match('#\((.*?)\)#', $full_view_name, $match);
preg_match('#\((.*?)\)#', $view_name, $match);
if (!empty($match)) {
$options = $this->getViewDisplays($match[1]);
}
else {
$options = $this->getViewDisplays($field_value['target_id']);
$view_name = $match[1];
}
$options = $this->getViewDisplays($view_name);
}
$element['display_id'] = [
'#title' => $this->t('Display'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $default_value,
'#default_value' => $display_id,
'#empty_option' => '- Select -',
'#empty_value' => '',
'#weight' => 10,
......@@ -148,12 +146,15 @@ trait ViewsReferenceTrait {
if (!empty($plugin_definitions[$enabled_setting])) {
$plugin_definition = $plugin_definitions[$enabled_setting];
/** @var \Drupal\viewsreference\Plugin\ViewsReferenceSettingInterface $plugin_instance */
$plugin_instance = $viewsreference_plugin_manager->createInstance($plugin_definition['id']);
$plugin_instance = $viewsreference_plugin_manager->createInstance($plugin_definition['id'], [
'view_name' => $view_name,
'display_id' => $display_id,
]);
$element['options'][$plugin_definition['id']] = [
'#title' => $plugin_definition['label'],
'#type' => 'textfield',
'#default_value' => isset($field_data[$plugin_definition['id']]) ? $field_data[$plugin_definition['id']] : $plugin_definition['default_value'],
'#default_value' => $field_data[$plugin_definition['id']] ?? $plugin_definition['default_value'],
'#states' => [
'visible' => [
':input[name="' . $target_id_name_string . '"]' => $view_selected_js_state,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment