diff --git a/ds.module b/ds.module index 34a5cb77..2450669f 100644 --- a/ds.module +++ b/ds.module @@ -27,15 +27,13 @@ use Drupal\field\Entity\FieldConfig; * Implements hook_help(). */ function ds_help($route_name, RouteMatchInterface $route_match) { - switch ($route_name) { - case 'help.page.ds': - $output = ''; - $output .= '

' . t('About') . '

'; - $output .= '
' . t('The Display Suite module allows you to take full control over how your content is displayed using a drag and drop interface. Arrange your nodes, views, comments, user data etc. the way you want without having to work your way through dozens of template files.', [':link' => 'https://www.drupal.org/project/ds']); - $output .= '
' . t('It allows you to apply theme templates to content type displays. It comes with predefined layouts such as "two columns", "three columns stacked", "three columns fluid" et cetera, but also lets you define your own.'); - $output .= '
' . t('Display Suite allows you to create fields from tokens or blocks. This gives you full control over the way content is displayed without having to maintain dozens of twig files.'); - $output .= '
' . t('More documentation about Display Suite in Drupal 8 can be found in Drupal\'s Community Documentation .', [':documentation' => 'https://www.drupal.org/node/2718943']); - return $output; + if ($route_name == 'help.page.ds') { + $output = '

' . t('About') . '

'; + $output .= '
' . t('The Display Suite module allows you to take full control over how your content is displayed using a drag and drop interface. Arrange your nodes, views, comments, user data etc. the way you want without having to work your way through dozens of template files.', [':link' => 'https://www.drupal.org/project/ds']); + $output .= '
' . t('It allows you to apply theme templates to entity type displays. It comes with predefined layouts such as "two columns", "three columns stacked", "three columns fluid" et cetera, but also lets you define your own.'); + $output .= '
' . t('Display Suite allows you to create fields from tokens or blocks. This gives you full control over the way content is displayed without having to maintain dozens of twig files.'); + $output .= '
' . t('More documentation about Display Suite in Drupal 8 can be found in Drupal\'s Community Documentation .', [':documentation' => 'https://www.drupal.org/node/2718943']); + return $output; } } @@ -173,7 +171,7 @@ function ds_theme_registry_alter(&$theme_registry) { continue; } - $pattern = isset($info['pattern']) ? $info['pattern'] : ($hook . '__'); + $pattern = $info['pattern'] ?? ($hook . '__'); if (!empty($pattern)) { // Transform _ in pattern to - to match file naming scheme // for the purposes of searching. @@ -291,7 +289,7 @@ function ds_entity_view_alter(&$build, EntityInterface $entity, EntityDisplayInt $configuration = $display->getThirdPartySettings('ds'); // Don't fatal on missing layout plugins. - $layout_id = isset($configuration['layout']['id']) ? $configuration['layout']['id'] : ''; + $layout_id = $configuration['layout']['id'] ?? ''; if (!Ds::layoutExists($layout_id)) { return; } @@ -377,8 +375,8 @@ function ds_entity_view_alter(&$build, EntityInterface $entity, EntityDisplayInt '#theme' => 'field', '#field_type' => 'ds', '#title' => $field_title, - '#weight' => isset($field_values[$key]['weight']) ? $field_values[$key]['weight'] : $weight, - '#label_display' => isset($field_values[$key]['label']) ? $field_values[$key]['label'] : 'inline', + '#weight' => $field_values[$key]['weight'] ?? $weight, + '#label_display' => $field_values[$key]['label'] ?? 'inline', '#field_name' => $key, '#bundle' => $bundle, '#object' => $entity, @@ -387,7 +385,7 @@ function ds_entity_view_alter(&$build, EntityInterface $entity, EntityDisplayInt '#ds_view_mode' => $view_mode, '#items' => [(object) ['_attributes' => []]], '#is_multiple' => $field_instance->isMultiple(), - '#access' => ($field_permissions && function_exists('ds_extras_ds_field_access')) ? ds_extras_ds_field_access($key, $entity_type) : TRUE, + '#access' => !($field_permissions && function_exists('ds_extras_ds_field_access')) || ds_extras_ds_field_access($key, $entity_type), '#formatter' => 'ds_field', ]; @@ -453,7 +451,7 @@ function template_preprocess_ds_entity_view(&$variables) { } } - /* @var \Drupal\layout_plugin\Plugin\Layout\LayoutInterface $layout */ + /* @var \Drupal\Core\Layout\LayoutInterface $layout */ $layout = \Drupal::service('plugin.manager.core.layout')->createInstance($configuration['layout']['id'], $configuration['layout']['settings']); $build = array_merge($build, $layout->build($regions)); @@ -480,7 +478,7 @@ function ds_preprocess_ds_layout(&$variables) { // Fetch the entity type. $bundle = FALSE; - $entity_type_id = FALSE; + $entity_type_id = NULL; if (isset($variables['content']['#entity_type'])) { $entity_type_id = $variables['content']['#entity_type']; } @@ -503,8 +501,6 @@ function ds_preprocess_ds_layout(&$variables) { // Create region variables based on the layout settings. if (!empty($layout_settings['wrappers']) && is_array($layout_settings['wrappers'])) { foreach ($layout_settings['wrappers'] as $region_name => $wrapper) { - // @todo remove from D9, This is deprecated - $variables[$region_name . '_classes'] = !empty($layout_settings['classes'][$region_name]) ? ' ' . implode(' ', $layout_settings['classes'][$region_name]) : ''; // The new way of doing stuff is creating an attributes object. if (!empty($layout_settings['classes'][$region_name])) { $variables[$region_name . '_attributes'] = new Attribute(['class' => $layout_settings['classes'][$region_name]]); @@ -517,7 +513,7 @@ function ds_preprocess_ds_layout(&$variables) { } // Add a layout wrapper. - $variables['outer_wrapper'] = isset($layout_settings['outer_wrapper']) ? $layout_settings['outer_wrapper'] : 'div'; + $variables['outer_wrapper'] = $layout_settings['outer_wrapper'] ?? 'div'; // Add custom attributes if any. if (!empty($layout_settings['attributes'])) { @@ -592,7 +588,7 @@ function ds_preprocess_ds_layout(&$variables) { // RDF support. if ($entity_type_id == 'node' && function_exists('rdf_preprocess_node')) { - $entity = isset($variables[$entity_type_id]) ? $variables[$entity_type_id] : (isset($variables['content']['#' . $entity_type_id]) ? $variables['content']['#' . $entity_type_id] : ''); + $entity = $variables[$entity_type_id] ?? (isset($variables['content']['#' . $entity_type_id]) ? $variables['content']['#' . $entity_type_id] : ''); if ($entity) { $variables['node'] = $entity; // We disable the date feature for now as it throws notices. @@ -708,7 +704,7 @@ function ds_local_tasks_alter(&$local_tasks) { function ds_preprocess_field(&$variables) { $entity_type = $variables['element']['#entity_type']; $bundle = $variables['element']['#bundle']; - $view_mode = isset($variables['element']['#ds_view_mode']) ? $variables['element']['#ds_view_mode'] : $variables['element']['#view_mode']; + $view_mode = $variables['element']['#ds_view_mode'] ?? $variables['element']['#view_mode']; /* @var $entity_display EntityDisplayInterface */ $entity_display = Ds::getDisplay($entity_type, $bundle, $view_mode); @@ -797,7 +793,7 @@ function ds_preprocess_field(&$variables) { function ds_theme_suggestions_field_alter(&$suggestions, $variables) { $entity_type = $variables['element']['#entity_type']; $bundle = $variables['element']['#bundle']; - $view_mode = isset($variables['element']['#ds_view_mode']) ? $variables['element']['#ds_view_mode'] : $variables['element']['#view_mode']; + $view_mode = $variables['element']['#ds_view_mode'] ?? $variables['element']['#view_mode']; /* @var $entity_display EntityDisplayInterface */ $entity_display = Ds::getDisplay($entity_type, $bundle, $view_mode); @@ -919,7 +915,7 @@ function ds_field_template_settings_form(array &$form, FormStateInterface &$form } else { $plugin_settings = $form_state->get('plugin_settings'); - $field_settings = isset($plugin_settings[$key]['ft']) ? $plugin_settings[$key]['ft'] : []; + $field_settings = $plugin_settings[$key]['ft'] ?? []; } // In case with an ajax refresh we fetch the function from a different place. @@ -934,7 +930,7 @@ function ds_field_template_settings_form(array &$form, FormStateInterface &$form $field_function = $values['settings']['formatter']['third_party_settings']['ds']['ft']['id']; } else { - $field_function = isset($field_settings['id']) ? $field_settings['id'] : $default_field_function; + $field_function = $field_settings['id'] ?? $default_field_function; } if (!isset($functions[$field_function])) { @@ -968,7 +964,7 @@ function ds_field_template_settings_form(array &$form, FormStateInterface &$form } // Create field layout plugin instance. - $config = isset($field_settings['settings']) ? $field_settings['settings'] : []; + $config = $field_settings['settings'] ?? []; $field_layout_instance = \Drupal::service('plugin.manager.ds.field.layout')->createInstance($field_function, $config); // Alter the form to add specific field layout settings. @@ -1098,14 +1094,14 @@ function template_preprocess_field__ds_field_reset(&$variables) { * Implements template_preprocess_ds_field_minimal(). */ function template_preprocess_field__ds_field_minimal(&$variables) { - $variables['settings'] = isset($variables['ds-config']['settings']) ? $variables['ds-config']['settings'] : []; + $variables['settings'] = $variables['ds-config']['settings'] ?? []; } /** * Implements template_preprocess_ds_field_expert(). */ function template_preprocess_field__ds_field_expert(&$variables) { - $variables['settings'] = isset($variables['ds-config']['settings']) ? $variables['ds-config']['settings'] : []; + $variables['settings'] = $variables['ds-config']['settings'] ?? []; $vars = [ 'lbw' => 'label_attributes', diff --git a/includes/field_ui.inc b/includes/field_ui.inc index db2aeb34..cd169edb 100644 --- a/includes/field_ui.inc +++ b/includes/field_ui.inc @@ -150,7 +150,7 @@ function ds_field_ui_regions(array $form, FormStateInterface $form_state) { } // Check layout. - $layout = isset($form['#ds_layout']) ? $form['#ds_layout'] : FALSE; + $layout = $form['#ds_layout'] ?? FALSE; // Build an array which keys are the field names and // values are the region they are rendered in. @@ -273,7 +273,7 @@ function ds_field_ui_regions(array $form, FormStateInterface $form_state) { * The region. */ function ds_field_ui_row_region(array $row) { - return isset($row['region']['#value']) ? $row['region']['#value'] : 'hidden'; + return $row['region']['#value'] ?? 'hidden'; } /** @@ -291,9 +291,9 @@ function ds_field_ui_layouts_validate($form, FormStateInterface $form_state) { // Only validate the layout settings if the layout hasn't changed. if (!$new_layout && !empty($layout)) { - /* @var \Drupal\layout_plugin\Plugin\Layout\LayoutInterface $layout_plugin */ + /* @var \Drupal\Core\Layout\LayoutInterface $layout_plugin */ $layout_plugin = \Drupal::service('plugin.manager.core.layout')->createInstance($form_state->getValue('ds_layout'), []); - $layout_form = isset($form['layout_configuration']) ? $form['layout_configuration'] : []; + $layout_form = $form['layout_configuration'] ?? []; foreach (Element::children($form) as $name) { if (!empty($form[$name]['#ds_layout_configuration'])) { $layout_form[$name] = $form[$name]; @@ -459,7 +459,7 @@ function ds_field_ui_layouts_save($form, FormStateInterface $form_state) { $fields = _ds_sort_fields((array) $form_state->getValue('fields'), 'weight'); foreach ($fields as $key => $field) { - // Make sure to hide hidden fields. + // Make sure to hide 'hidden' fields. if ($field['region'] == 'hidden') { $form_state->setValue(['fields', $key, 'type'], 'hidden'); continue; @@ -471,9 +471,9 @@ function ds_field_ui_layouts_save($form, FormStateInterface $form_state) { $record['regions'][$field['region']][] = $key; } - /* @var \Drupal\layout_plugin\Plugin\Layout\LayoutInterface $layout_plugin */ + /* @var \Drupal\Core\Layout\LayoutInterface $layout_plugin */ $layout_plugin = \Drupal::service('plugin.manager.core.layout')->createInstance($layout, []); - $layout_form = isset($form['layout_configuration']) ? $form['layout_configuration'] : []; + $layout_form = $form['layout_configuration'] ?? []; foreach (Element::children($form) as $name) { if (!empty($form[$name]['#ds_layout_configuration'])) { $layout_form[$name] = $form[$name]; @@ -585,13 +585,13 @@ function ds_field_ui_fields_save($form, FormStateInterface $form_state) { unset($field_settings[$field]['settings']['ft']); // Add field template plugin settings if provided. - $values = isset($all_plugin_settings[$field]['ft']) ? $all_plugin_settings[$field]['ft'] : []; + $values = $all_plugin_settings[$field]['ft'] ?? []; if (!empty($values)) { $field_settings[$field]['ft'] = $values; $default_field_function = \Drupal::config('ds.settings')->get('ft-default'); - $function = isset($values['id']) ? $values['id'] : $default_field_function; + $function = $values['id'] ?? $default_field_function; $field_settings[$field]['ft']['id'] = $function; // It's important for schema validation to never save empty arrays. @@ -907,7 +907,7 @@ function _ds_field_ui_table_layouts($entity_type, $bundle, $view_mode, array &$f $form['ds_layouts']['old_layout'] = [ '#type' => 'value', - '#value' => isset($layout['layout']) ? $layout['layout'] : 0, + '#value' => $layout['layout'] ?? 0, ]; // Add validate and submit handlers. Layout needs be first so diff --git a/modules/ds_extras/src/Plugin/DsField/SwitchField.php b/modules/ds_extras/src/Plugin/DsField/SwitchField.php index 98eff1d7..2e2780f2 100644 --- a/modules/ds_extras/src/Plugin/DsField/SwitchField.php +++ b/modules/ds_extras/src/Plugin/DsField/SwitchField.php @@ -128,7 +128,7 @@ class SwitchField extends DsFieldBase { ]; $config = $this->getConfiguration(); - $config = isset($config['vms']) ? $config['vms'] : []; + $config = $config['vms'] ?? []; foreach ($view_modes as $key => $value) { $entity_display = $this->entityTypeManager ->getStorage('entity_view_display') @@ -137,7 +137,7 @@ class SwitchField extends DsFieldBase { if ($entity_display->status()) { $form['vms'][$key] = [ '#type' => 'textfield', - '#default_value' => isset($config[$key]) ? $config[$key] : '', + '#default_value' => $config[$key] ?? '', '#size' => 20, '#title' => Html::escape($value['label']), ]; @@ -154,7 +154,7 @@ class SwitchField extends DsFieldBase { public function settingsSummary($settings) { $entity_type = $this->getEntityTypeId(); $bundle = $this->bundle(); - $settings = isset($settings['vms']) ? $settings['vms'] : []; + $settings = $settings['vms'] ?? []; $view_modes = $this->entityDisplayRepository->getViewModes($entity_type); $summary = []; @@ -166,7 +166,7 @@ class SwitchField extends DsFieldBase { ->load($entity_type . '.' . $bundle . '.' . $key); if (!empty($entity_display)) { if ($entity_display->status()) { - $label = isset($settings[$key]) ? $settings[$key] : $key; + $label = $settings[$key] ?? $key; $summary[] = $key . ' : ' . $label; } } diff --git a/modules/ds_switch_view_mode/ds_switch_view_mode.module b/modules/ds_switch_view_mode/ds_switch_view_mode.module index b1f5902a..8bc3b482 100644 --- a/modules/ds_switch_view_mode/ds_switch_view_mode.module +++ b/modules/ds_switch_view_mode/ds_switch_view_mode.module @@ -111,12 +111,7 @@ function ds_switch_view_mode_form_node_form_alter(&$form, FormStateInterface $fo } $chosen_layout = $layouts[$mode]; if (empty($chosen_layout)) { - if (isset($layouts['full'])) { - $chosen_layout = $layouts['full']; - } - else { - $chosen_layout = $layouts['']; - } + $chosen_layout = $layouts['full'] ?? $layouts['']; } $layout_settings = $chosen_layout->getThirdPartySettings('ds'); diff --git a/src/Controller/FieldController.php b/src/Controller/FieldController.php index b42a8811..93375ba6 100644 --- a/src/Controller/FieldController.php +++ b/src/Controller/FieldController.php @@ -68,7 +68,7 @@ class FieldController extends ControllerBase implements ContainerInjectionInterf '#plain_text' => $field_value['label'], ], ]; - $row[] = isset($field_value['type_label']) ? $field_value['type_label'] : $this->t('Unknown'); + $row[] = $field_value['type_label'] ?? $this->t('Unknown'); $row[] = $field_value['id']; $row[] = ucwords(str_replace('_', ' ', implode(', ', $field_value['entities']))); diff --git a/src/Ds.php b/src/Ds.php index 9d528de8..c0558002 100644 --- a/src/Ds.php +++ b/src/Ds.php @@ -38,7 +38,7 @@ class Ds { } } - return isset($static_fields[$entity_type]) ? $static_fields[$entity_type] : []; + return $static_fields[$entity_type] ?? []; } /** @@ -75,7 +75,7 @@ class Ds { /* @var $display \Drupal\Core\Entity\Display\EntityDisplayInterface */ if ($field_settings = $display->getThirdPartySetting('ds', 'fields')) { - $settings = isset($field_settings[$key]['settings']) ? $field_settings[$key]['settings'] : []; + $settings = $field_settings[$key]['settings'] ?? []; // Unset field template settings. if (isset($settings['ft'])) { unset($settings['ft']); @@ -119,7 +119,7 @@ class Ds { */ public static function layoutExists($id) { $layouts = self::getLayouts(); - return isset($layouts[$id]) ? TRUE : FALSE; + return isset($layouts[$id]); } /** diff --git a/src/Form/BlockFieldForm.php b/src/Form/BlockFieldForm.php index 3f959584..03b9b1c3 100644 --- a/src/Form/BlockFieldForm.php +++ b/src/Form/BlockFieldForm.php @@ -46,20 +46,20 @@ class BlockFieldForm extends FieldFormBase implements ContainerInjectionInterfac '#options' => $blocks, '#title' => $this->t('Block'), '#required' => TRUE, - '#default_value' => isset($field['properties']['block']) ? $field['properties']['block'] : '', + '#default_value' => $field['properties']['block'] ?? '', ]; $form['use_block_title'] = [ '#type' => 'checkbox', '#title' => $this->t('Use block title as the field label'), - '#default_value' => isset($field['properties']['use_block_title']) ? $field['properties']['use_block_title'] : FALSE, + '#default_value' => $field['properties']['use_block_title'] ?? FALSE, '#weight' => 90, ]; $form['add_block_wrappers'] = [ '#type' => 'checkbox', '#title' => $this->t('Add block wrappers and classes'), - '#default_value' => isset($field['properties']['add_block_wrappers']) ? $field['properties']['add_block_wrappers'] : FALSE, + '#default_value' => $field['properties']['add_block_wrappers'] ?? FALSE, '#description' => $this->t('Render using the block theme hook to add the block wrappers and clases.'), '#weight' => 91, ]; diff --git a/src/Form/CopyFieldForm.php b/src/Form/CopyFieldForm.php index e3f4057a..fc4c0e9e 100644 --- a/src/Form/CopyFieldForm.php +++ b/src/Form/CopyFieldForm.php @@ -45,7 +45,7 @@ class CopyFieldForm extends FieldFormBase { '#options' => $fields, '#title' => $this->t('Fields'), '#required' => TRUE, - '#default_value' => isset($field['properties']['ds_plugin']) ? $field['properties']['ds_plugin'] : '', + '#default_value' => $field['properties']['ds_plugin'] ?? '', ]; return $form; diff --git a/src/Form/FieldFormBase.php b/src/Form/FieldFormBase.php index 367350de..218b4cda 100644 --- a/src/Form/FieldFormBase.php +++ b/src/Form/FieldFormBase.php @@ -102,7 +102,7 @@ class FieldFormBase extends ConfigFormBase implements ContainerInjectionInterfac $form['name'] = [ '#title' => $this->t('Label'), '#type' => 'textfield', - '#default_value' => isset($field['label']) ? $field['label'] : '', + '#default_value' => $field['label'] ?? '', '#description' => $this->t('The human-readable label of the field.'), '#maxlength' => 128, '#required' => TRUE, @@ -111,7 +111,7 @@ class FieldFormBase extends ConfigFormBase implements ContainerInjectionInterfac $form['id'] = [ '#type' => 'machine_name', - '#default_value' => isset($field['id']) ? $field['id'] : '', + '#default_value' => $field['id'] ?? '', '#maxlength' => 32, '#description' => $this->t('The machine-readable name of this field. This name must contain only lowercase letters and underscores. This name must be unique.'), '#disabled' => !empty($field['id']), @@ -134,14 +134,14 @@ class FieldFormBase extends ConfigFormBase implements ContainerInjectionInterfac '#type' => 'checkboxes', '#required' => TRUE, '#options' => $entity_options, - '#default_value' => isset($field['entities']) ? $field['entities'] : [], + '#default_value' => $field['entities'] ?? [], ]; $form['ui_limit'] = [ '#title' => $this->t('Limit field'), '#description' => $this->t('Limit this field on field UI per bundles and/or view modes. The values are in the form of $bundle|$view_mode, where $view_mode may be either a view mode set to use custom settings, or \'default\'. You may use * to select all, e.g article|*, *|full or *|*. Enter one value per line.'), '#type' => 'textarea', - '#default_value' => isset($field['ui_limit']) ? $field['ui_limit'] : '', + '#default_value' => $field['ui_limit'] ?? '', ]; $form['submit'] = [ diff --git a/src/Form/TokenFieldForm.php b/src/Form/TokenFieldForm.php index ed576928..2ea0b2fe 100644 --- a/src/Form/TokenFieldForm.php +++ b/src/Form/TokenFieldForm.php @@ -31,8 +31,8 @@ class TokenFieldForm extends FieldFormBase { $form['content'] = [ '#type' => 'text_format', '#title' => $this->t('Field content'), - '#default_value' => isset($field['properties']['content']['value']) ? $field['properties']['content']['value'] : '', - '#format' => isset($field['properties']['content']['format']) ? $field['properties']['content']['format'] : 'plain_text', + '#default_value' => $field['properties']['content']['value'] ?? '', + '#format' => $field['properties']['content']['format'] ?? 'plain_text', '#base_type' => 'textarea', '#required' => TRUE, ]; diff --git a/src/Form/TwigFieldForm.php b/src/Form/TwigFieldForm.php index 3f4d716c..9579a2c1 100644 --- a/src/Form/TwigFieldForm.php +++ b/src/Form/TwigFieldForm.php @@ -32,7 +32,7 @@ class TwigFieldForm extends FieldFormBase { '#type' => 'textarea', '#title' => $this->t('Template'), '#rows' => 5, - '#default_value' => isset($field['properties']['content']) ? $field['properties']['content'] : '', + '#default_value' => $field['properties']['content'] ?? '', '#required' => TRUE, ]; diff --git a/src/Plugin/DsField/BlockBase.php b/src/Plugin/DsField/BlockBase.php index 06b14a34..f5f106c3 100644 --- a/src/Plugin/DsField/BlockBase.php +++ b/src/Plugin/DsField/BlockBase.php @@ -79,7 +79,7 @@ abstract class BlockBase extends DsFieldBase implements ContainerFactoryPluginIn $block_config = $this->blockConfig(); $block->setConfiguration($block_config); - $add_wrappers = isset($this->getFieldConfiguration()['properties']['add_block_wrappers']) ? $this->getFieldConfiguration()['properties']['add_block_wrappers'] : FALSE; + $add_wrappers = isset($this->getFieldConfiguration()['properties']['add_block_wrappers']) && $this->getFieldConfiguration()['properties']['add_block_wrappers']; if ($block->access(\Drupal::currentUser())) { // Inject context values. diff --git a/src/Plugin/DsField/DynamicBlockField.php b/src/Plugin/DsField/DynamicBlockField.php index 3bd139c5..605931a9 100644 --- a/src/Plugin/DsField/DynamicBlockField.php +++ b/src/Plugin/DsField/DynamicBlockField.php @@ -43,8 +43,8 @@ class DynamicBlockField extends BlockBase { $field = $this->getFieldConfiguration(); $title = $field['title']; - if (isset($field['properties']['use_block_title']) && $field['properties']['use_block_title'] == TRUE) { - /* @var $block BlockPluginInterface */ + if (isset($field['properties']['use_block_title']) && $field['properties']['use_block_title']) { + /* @var $block \Drupal\Core\Block\BlockPluginInterface */ $block = $this->getBlock(); if ($block instanceof ViewsBlock) { diff --git a/src/Plugin/DsFieldTemplate/Expert.php b/src/Plugin/DsFieldTemplate/Expert.php index a1e594c4..25435475 100644 --- a/src/Plugin/DsFieldTemplate/Expert.php +++ b/src/Plugin/DsFieldTemplate/Expert.php @@ -33,7 +33,7 @@ class Expert extends DsFieldTemplateBase { '#title' => $this->t('Prefix'), '#size' => '100', '#description' => $this->t('You can enter any html in here.'), - '#default_value' => isset($config['prefix']) ? $config['prefix'] : '', + '#default_value' => $config['prefix'] ?? '', '#prefix' => '
', '#suffix' => '
', ]; @@ -145,7 +145,7 @@ class Expert extends DsFieldTemplateBase { '#title' => $this->t('Suffix'), '#size' => '100', '#description' => $this->t('You can enter any html in here.'), - '#default_value' => isset($config['suffix']) ? $config['suffix'] : '', + '#default_value' => $config['suffix'] ?? '', '#prefix' => '
', '#suffix' => '
', ]; diff --git a/src/Plugin/DsLayout.php b/src/Plugin/DsLayout.php index dc9117e7..4e0a731f 100644 --- a/src/Plugin/DsLayout.php +++ b/src/Plugin/DsLayout.php @@ -155,7 +155,7 @@ class DsLayout extends LayoutDefault implements PluginFormInterface { if (!empty($classes)) { $layoutSettings = $this->getPluginDefinition()->get('settings') ?: []; - $default_layout_classes = isset($layoutSettings['classes']['layout_class']) ? $layoutSettings['classes']['layout_class'] : []; + $default_layout_classes = $layoutSettings['classes']['layout_class'] ?? []; $form['ds_classes']['layout_class'] = [ '#type' => 'select', '#multiple' => TRUE, @@ -165,13 +165,13 @@ class DsLayout extends LayoutDefault implements PluginFormInterface { ]; foreach ($regions as $region_name => $region_definition) { - $default_classes = isset($layoutSettings['classes'][$region_name]) ? $layoutSettings['classes'][$region_name] : []; + $default_classes = $layoutSettings['classes'][$region_name] ?? []; $form['ds_classes'][$region_name] = [ '#type' => 'select', '#multiple' => TRUE, '#options' => $classes, '#title' => $this->t('Class for @region', ['@region' => $region_definition['label']]), - '#default_value' => isset($configuration['classes'][$region_name]) ? $configuration['classes'][$region_name] : $default_classes, + '#default_value' => $configuration['classes'][$region_name] ?? $default_classes, ]; } if ($classes_access) { diff --git a/src/Plugin/views/Entity/Render/RendererBase.php b/src/Plugin/views/Entity/Render/RendererBase.php index f06f6ff8..a76e4a4d 100644 --- a/src/Plugin/views/Entity/Render/RendererBase.php +++ b/src/Plugin/views/Entity/Render/RendererBase.php @@ -41,7 +41,7 @@ abstract class RendererBase extends EntityTranslationRendererBase { protected function alterBuild(&$build, $row) { // Add row index. Remember that in case you want to use this, you will // have to remove the cache for this build. - $build['#row_index'] = isset($row->index) ? $row->index : NULL; + $build['#row_index'] = $row->index ?? NULL; // Delta fields. $delta_fields = $this->view->rowPlugin->options['delta_fieldset']['delta_fields']; @@ -99,7 +99,7 @@ abstract class RendererBase extends EntityTranslationRendererBase { $view_mode = $this->view->rowPlugin->options['view_mode']; } else { - $view_mode = isset($this->view->rowPlugin->options['alternating_fieldset']['item_' . $i]) ? $this->view->rowPlugin->options['alternating_fieldset']['item_' . $i] : $this->view->rowPlugin->options['view_mode']; + $view_mode = $this->view->rowPlugin->options['alternating_fieldset']['item_' . $i] ?? $this->view->rowPlugin->options['view_mode']; } $i++; } @@ -164,7 +164,7 @@ abstract class RendererBase extends EntityTranslationRendererBase { $group_field = mb_substr($group_field, 0, 60); } - $raw_group_value = isset($row->{$group_field}) ? $row->{$group_field} : ''; + $raw_group_value = $row->{$group_field} ?? ''; $group_value = $raw_group_value; // Special function to format the heading value. diff --git a/src/Plugin/views/Entity/Render/TranslationLanguageRenderer.php b/src/Plugin/views/Entity/Render/TranslationLanguageRenderer.php index 7d4bb7c4..9f7f1202 100644 --- a/src/Plugin/views/Entity/Render/TranslationLanguageRenderer.php +++ b/src/Plugin/views/Entity/Render/TranslationLanguageRenderer.php @@ -65,7 +65,8 @@ class TranslationLanguageRenderer extends DefaultLanguageRenderer { * {@inheritdoc} */ public function getLangcode(ResultRow $row) { - return isset($row->{$this->langcodeAlias}) ? $row->{$this->langcodeAlias} : $this->languageManager->getDefaultLanguage()->getId(); + return $row->{$this->langcodeAlias} ?? $this->languageManager->getDefaultLanguage() + ->getId(); } } diff --git a/src/Plugin/views/row/EntityRow.php b/src/Plugin/views/row/EntityRow.php index 88275a7d..09dec03e 100644 --- a/src/Plugin/views/row/EntityRow.php +++ b/src/Plugin/views/row/EntityRow.php @@ -174,13 +174,13 @@ class EntityRow extends ViewsEntityRow { $form['grouping_fieldset']['group_field'] = [ '#type' => 'select', '#options' => $sort_options, - '#default_value' => isset($this->options['grouping_fieldset']['group_field']) ? $this->options['grouping_fieldset']['group_field'] : '', + '#default_value' => $this->options['grouping_fieldset']['group_field'] ?? '', ]; $form['grouping_fieldset']['group_field_function'] = [ '#type' => 'textfield', '#title' => 'Heading function', '#description' => Html::escape(t('The value of the field can be in a very raw format (eg, date created). Enter a custom function which you can use to format that value. The value and the object will be passed into that function eg. custom_function($raw_value, $object);')), - '#default_value' => isset($this->options['grouping_fieldset']['group_field_function']) ? $this->options['grouping_fieldset']['group_field_function'] : '', + '#default_value' => $this->options['grouping_fieldset']['group_field_function'] ?? '', ]; } else {