Skip to content
Snippets Groups Projects

Fixed some PHPCS and Dependecy Injections problems.

Files
76
+ 45
37
@@ -5,7 +5,6 @@
* Field UI functions for Display Suite.
*/
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
@@ -20,7 +19,6 @@ use Drupal\ds\Plugin\DsField\DsFieldInterface;
use Drupal\field\FieldConfigInterface;
use Drupal\field_ui\FieldUI;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Link;
use Drupal\layout_builder\LayoutBuilderEnabledInterface;
/**
@@ -33,9 +31,9 @@ function ds_field_ui_fields_layouts(&$form, FormStateInterface $form_state) {
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
/* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
/** @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
$entity_form = $form_state->getFormObject();
/* @var \Drupal\Core\Entity\Display\EntityDisplayInterface $entity_display */
/** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $entity_display */
$entity_display = $entity_form->getEntity();
$view_mode = $entity_display->getMode();
@@ -131,9 +129,9 @@ function ds_field_ui_regions(array $form, FormStateInterface $form_state) {
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
/* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
/** @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
$entity_form = $form_state->getFormObject();
/* @var \Drupal\Core\Entity\Display\EntityDisplayInterface $entity_display */
/** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $entity_display */
$entity_display = $entity_form->getEntity();
$view_mode = $entity_display->getMode();
@@ -233,7 +231,7 @@ function ds_field_ui_regions(array $form, FormStateInterface $form_state) {
}
// Add region.
// Core added regions to Field UI, which default to 'content'
// Core added regions to Field UI, which default to 'content'.
if (!isset($row['region'])) {
$split = 7;
$default = (isset($field_regions[$name]) && isset($region_options[$field_regions[$name]])) ? $field_regions[$name] : 'hidden';
@@ -285,7 +283,7 @@ 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\Core\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 = $form['layout_configuration'] ?? [];
foreach (Element::children($form) as $name) {
@@ -295,8 +293,10 @@ function ds_field_ui_layouts_validate($form, FormStateInterface $form_state) {
}
if ($layout_plugin instanceof PluginFormInterface) {
$layout_form_state = (new FormState())->setValues($form_state->getValue('layout_configuration', []));
// TODO
//$layout_plugin->validateConfigurationForm($layout_form, $layout_form_state);
$layout_form_state = $layout_form_state;
// @todo Fix
// $layout_plugin->validateConfigurationForm($layout_form,
// $layout_form_state);
}
}
@@ -318,11 +318,11 @@ function ds_field_ui_layouts_save($form, FormStateInterface $form_state) {
// Get default values.
$entity_type = $form['#entity_type'];
/* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
/** @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
$entity_form = $form_state->getFormObject();
// Get the entity display.
/* @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
/** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
$display = $entity_form->getEntity();
if ($display instanceof LayoutBuilderEnabledInterface && $display->isLayoutBuilderEnabled()) {
@@ -401,6 +401,7 @@ function ds_field_ui_layouts_save($form, FormStateInterface $form_state) {
$layouts = Ds::getLayouts();
/** @var \Drupal\Core\Layout\LayoutDefinition $sl */
$sl = $layouts[$layout];
// @todo use default region method?
$first_region = key($sl->getRegions());
$record['layout']['settings']['classes'] = [];
$record['layout']['settings']['wrappers'] = [];
@@ -456,7 +457,7 @@ function ds_field_ui_layouts_save($form, FormStateInterface $form_state) {
$record['regions'][$field['region']][] = $key;
}
/* @var \Drupal\Core\Layout\LayoutInterface $layout_plugin */
/** @var \Drupal\Core\Layout\LayoutInterface $layout_plugin */
$layout_plugin = \Drupal::service('plugin.manager.core.layout')->createInstance($layout, []);
$layout_form = $form['layout_configuration'] ?? [];
foreach (Element::children($form) as $name) {
@@ -523,9 +524,9 @@ function ds_field_ui_fields_save($form, FormStateInterface $form_state) {
}
// Get the entity display.
/* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
/** @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
$entity_form = $form_state->getFormObject();
/* @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
/** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
$display = $entity_form->getEntity();
$field_settings = [];
@@ -608,20 +609,20 @@ function ds_field_ui_fields_save($form, FormStateInterface $form_state) {
*/
function ds_field_ui_layout_clone($form, FormStateInterface $form_state) {
$clone = $form_state->getValue('clone');
list(, , $cv) = explode('.', $clone);
[, , $cv] = explode('.', $clone);
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
/* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
/** @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
$entity_form = $form_state->getFormObject();
// Get the entity display.
/* @var \Drupal\Core\Entity\Display\EntityDisplayInterface $old_display */
/** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $old_display */
$old_display = $entity_form->getEntity();
$view_mode = $old_display->getMode();
$old_display->delete();
/* @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
$display = EntityViewDisplay::load($entity_type . '.' . $bundle . '.' . $cv);
$clone_display = $display->createCopy($view_mode);
@@ -649,7 +650,10 @@ function ds_field_settings_summary(DsFieldInterface $plugin_instance, array $set
$summary = $plugin_instance->settingsSummary($settings);
// Add field template summary.
ds_field_formatter_settings_summary_alter($summary, ['field_definition' => $plugin_instance, 'form_state' => $form_state]);
ds_field_formatter_settings_summary_alter($summary, [
'field_definition' => $plugin_instance,
'form_state' => $form_state,
]);
if (empty($summary)) {
return [];
@@ -767,9 +771,9 @@ function _ds_field_ui_table_layouts($entity_type, $bundle, $view_mode, array &$f
];
$layout = [];
/* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
/** @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
$entity_form = $form_state->getFormObject();
/* @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
$display = $entity_form->getEntity();
if ($display->getThirdPartySetting('ds', 'layout')) {
$layout_configuration = $display->getThirdPartySetting('ds', 'layout');
@@ -795,7 +799,7 @@ function _ds_field_ui_table_layouts($entity_type, $bundle, $view_mode, array &$f
_ds_field_ui_table_layouts_preview($form, $form_state, $ds_layouts, $layout, $display);
if (!empty($layout) && !empty($layout['settings'])) {
/* @var \Drupal\Core\Layout\LayoutInterface $layout_plugin */
/** @var \Drupal\Core\Layout\LayoutInterface $layout_plugin */
$layout_plugin = \Drupal::service('plugin.manager.core.layout')->createInstance($layout['layout'], $layout['settings'] ?: []);
if ($layout_plugin instanceof PluginFormInterface) {
@@ -920,7 +924,7 @@ function _ds_field_ui_table_layouts_preview(array &$form, FormStateInterface $fo
'#type' => 'select',
'#title' => t('Select a layout'),
'#options' => $layout['layout_options'],
'#default_value' => isset($layout['layout']) ? $layout['layout'] : NULL,
'#default_value' => $layout['layout'] ?? NULL,
'#empty_value' => '_none',
'#weight' => -1,
'#ajax' => [
@@ -991,8 +995,9 @@ function _ds_field_ui_table_layouts_preview(array &$form, FormStateInterface $fo
'class' => ['ds-layout-preview-suggestion'],
],
];
$templateSuggestion = t('Template suggestions');
$form['ds_layouts']['preview']['info']['suggestions'] = [
'#markup' => '<p>' . $selected . '</p><p>' . t('Template suggestions') . ':' . '</p>',
'#markup' => '<p>' . $selected . '</p><p>' . $templateSuggestion . ':' . '</p>',
];
$form['ds_layouts']['preview']['info']['suggestions_list'] = [
'#theme' => 'item_list',
@@ -1186,9 +1191,9 @@ function _ds_field_ui_fields($entity_type, $bundle, $view_mode, array &$form, Fo
];
\Drupal::moduleHandler()->alter('ds_label_options', $field_label_options);
/* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
/** @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
$entity_form = $form_state->getFormObject();
/* @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
$display = $entity_form->getEntity();
$parent_options = [];
@@ -1213,7 +1218,7 @@ function _ds_field_ui_fields($entity_type, $bundle, $view_mode, array &$form, Fo
];
// Check if we can display this field here.
/* @var $plugin_instance DsFieldInterface */
/** @var \Drupal\ds\DsFieldInterface $plugin_instance */
$plugin_instance = \Drupal::service('plugin.manager.ds')->createInstance($field['plugin_id'], $configuration);
if (!$plugin_instance->isAllowed()) {
@@ -1224,7 +1229,7 @@ function _ds_field_ui_fields($entity_type, $bundle, $view_mode, array &$form, Fo
if (!empty($displays)) {
$continue = TRUE;
foreach ($displays as $limitation) {
list($limit_bundle, $limit_view_mode) = explode('|', $limitation);
[$limit_bundle, $limit_view_mode] = explode('|', $limitation);
if ($limit_bundle == '*' || $limit_bundle == $bundle) {
if ($limit_view_mode == '*' || $limit_view_mode == $view_mode) {
$continue = FALSE;
@@ -1288,7 +1293,7 @@ function _ds_field_ui_fields($entity_type, $bundle, $view_mode, array &$form, Fo
],
'weight' => [
'#type' => 'textfield',
'#default_value' => isset($field_settings[$key]['weight']) ? $field_settings[$key]['weight'] : 0,
'#default_value' => $field_settings[$key]['weight'] ?? 0,
'#size' => 3,
'#attributes' => ['class' => ['field-weight']],
],
@@ -1297,7 +1302,7 @@ function _ds_field_ui_fields($entity_type, $bundle, $view_mode, array &$form, Fo
'#type' => 'select',
'#empty_value' => '',
'#options' => $parent_options,
'#default_value' => isset($field_group_params->parents[$key]) ? $field_group_params->parents[$key] : '',
'#default_value' => $field_group_params->parents[$key] ?? '',
'#attributes' => ['class' => ['field-parent']],
'#parents' => ['fields', $key, 'parent'],
],
@@ -1310,13 +1315,13 @@ function _ds_field_ui_fields($entity_type, $bundle, $view_mode, array &$form, Fo
'label' => [
'#type' => 'select',
'#options' => $field_label_options,
'#default_value' => isset($field_settings[$key]['label']) ? $field_settings[$key]['label'] : 'hidden',
'#default_value' => $field_settings[$key]['label'] ?? 'hidden',
],
'plugin' => [
'type' => [
'#type' => 'select',
'#options' => $formatters,
'#default_value' => isset($field_settings[$key]['formatter']) ? $field_settings[$key]['formatter'] : 'hidden',
'#default_value' => $field_settings[$key]['formatter'] ?? 'hidden',
'#attributes' => ['class' => ['field-plugin-type']],
],
],
@@ -1353,9 +1358,9 @@ function _ds_field_ui_fields($entity_type, $bundle, $view_mode, array &$form, Fo
function _ds_field_ui_core_fields(array &$form, FormStateInterface $form_state) {
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
/* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
/** @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
$entity_form = $form_state->getFormObject();
/* @var EntityViewDisplay $entity_display */
/** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $entity_display */
$entity_display = $entity_form->getEntity();
// Gather type information.
@@ -1380,7 +1385,7 @@ function _ds_field_ui_core_fields(array &$form, FormStateInterface $form_state)
// Import field settings and merge with Field API settings.
if (!isset($form_state_plugin_settings[$key])) {
$form_state_plugin_settings[$key] = isset($settings['third_party_settings']['ds']) ? $settings['third_party_settings']['ds'] : [];
$form_state_plugin_settings[$key] = $settings['third_party_settings']['ds'] ?? [];
}
if ($form_state->get('plugin_settings_edit') == $key) {
@@ -1468,7 +1473,10 @@ function ds_field_row_form_format_summary_construct(&$table, $key, FormStateInte
'#type' => 'image_button',
'#name' => $key . '_plugin_settings_edit',
'#src' => 'core/misc/icons/787878/cog.svg',
'#attributes' => ['class' => ['field-plugin-settings-edit'], 'alt' => t('Edit')],
'#attributes' => [
'class' => ['field-plugin-settings-edit'],
'alt' => t('Edit'),
],
'#op' => 'edit',
// Do not check errors for the 'Edit' button, but make sure we get
// the value of the 'plugin type' select.
Loading