From 74952839f28c520c301d90187d9efd705aef4af5 Mon Sep 17 00:00:00 2001 From: Artem Konotopchyk Date: Tue, 23 Sep 2025 17:50:29 +0300 Subject: [PATCH 1/2] Issue #3547982: add Drupal GitLab CI, fixed several errors --- .gitlab-ci.yml | 34 +++ editablefields.info.yml | 2 +- src/Controller/EditablefieldsController.php | 6 +- src/Form/EditableFieldsForm.php | 41 ++-- .../EditableFieldsFieldFormatter.php | 214 +++++++++--------- src/services/EditableFieldsHelper.php | 9 +- 6 files changed, 169 insertions(+), 137 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..795df11 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,34 @@ + +################ +# GitLabCI template for Drupal projects. +# +# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. +# It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained. +# As long as you include the project, ref and three files below, any future updates added by the Drupal Association will be used in your +# pipelines automatically. However, you can modify this template if you have additional needs for your project. +# The full documentation is on https://project.pages.drupalcode.org/gitlab_templates/ +################ +# For information on alternative values for 'ref' see https://project.pages.drupalcode.org/gitlab_templates/info/templates-version/ +# To test a Drupal 7 project, change the first include filename from .main.yml to .main-d7.yml +include: + - project: $_GITLAB_TEMPLATES_REPO + ref: $_GITLAB_TEMPLATES_REF + file: + - '/includes/include.drupalci.main.yml' + - '/includes/include.drupalci.variables.yml' + - '/includes/include.drupalci.workflows.yml' +# +################ +# Pipeline configuration variables are defined with default values and descriptions in the file +# https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml +# Uncomment the lines below if you want to override any of the variables. The following is just an example. +################ +variables: + OPT_IN_TEST_PREVIOUS_MAJOR: 1 + OPT_IN_TEST_PREVIOUS_MINOR: 1 + OPT_IN_TEST_NEXT_MINOR: 1 + OPT_IN_TEST_NEXT_MAJOR: 1 + OPT_IN_TEST_MAX_PHP: 0 + RUN_JOB_UPGRADE_STATUS: 1 + # Do not mark as an error: `behaviour` (british english), `subelement` (variable name), + _CSPELL_WORDS: 'behaviour,behaviours,subelement' diff --git a/editablefields.info.yml b/editablefields.info.yml index dc4ecd8..4ab2d3b 100644 --- a/editablefields.info.yml +++ b/editablefields.info.yml @@ -1,5 +1,5 @@ name: 'Editable Fields' type: module description: 'Allows you to make some fields editable from the display.' -core_version_requirement: ^8 || ^9 || ^10 || ^11 +core_version_requirement: ^10 || ^11 || ^12 package: 'Fields' diff --git a/src/Controller/EditablefieldsController.php b/src/Controller/EditablefieldsController.php index c2bb28e..ecf7c71 100644 --- a/src/Controller/EditablefieldsController.php +++ b/src/Controller/EditablefieldsController.php @@ -4,7 +4,6 @@ namespace Drupal\editablefields\Controller; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; -use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\editablefields\services\EditableFieldsHelper; @@ -16,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class EditablefieldsController extends ControllerBase { /** - * the EditableFieldsHelper service. + * The EditableFieldsHelper service. * * @var \Drupal\editablefields\services\EditableFieldsHelper */ @@ -60,7 +59,8 @@ class EditablefieldsController extends ControllerBase { $entity = $this->entityTypeManager ->getStorage($entity_type) ->load($entity_id); - } catch (InvalidPluginDefinitionException|PluginNotFoundException $e) { + } + catch (InvalidPluginDefinitionException | PluginNotFoundException $e) { return [ '#markup' => $this->t('Error occurred. Please contact site admin'), ]; diff --git a/src/Form/EditableFieldsForm.php b/src/Form/EditableFieldsForm.php index 7311d67..8c71cbe 100644 --- a/src/Form/EditableFieldsForm.php +++ b/src/Form/EditableFieldsForm.php @@ -6,7 +6,6 @@ use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\CloseModalDialogCommand; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\BaseFormIdInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -14,7 +13,7 @@ use Drupal\Core\Render\Element; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Class EditableFieldsForm. + * Form class EditableFieldsForm. */ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { @@ -30,19 +29,19 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { * * @var string */ - protected $field_name; + protected $fieldName; /** * Form mode. * * @var string */ - protected $form_mode; + protected $formMode; /** * Formatter settings. * - * @var array $settings + * @var array */ protected $settings; @@ -110,7 +109,7 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { * The field name. */ public function getFieldName() { - return $this->field_name; + return $this->fieldName; } /** @@ -120,7 +119,7 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { * The form mode. */ public function getFormMode() { - return $this->form_mode; + return $this->formMode; } /** @@ -147,7 +146,7 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { $operation = $form_state->get('operation'); - $field = $this->field_name; + $field = $this->fieldName; $form_display = $this->getFormDisplay(); $is_admin = $this->editablefieldsHelper->isAdmin(); @@ -155,7 +154,7 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { if ($is_admin) { return [ '#markup' => $this->t('Form mode @mode missing', [ - '@mode' => $this->form_mode, + '@mode' => $this->formMode, ]), ]; } @@ -164,7 +163,7 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { // If fallback formatter selected. if ($fallback && (!$operation || $operation === 'cancel')) { - /** @var FieldItemListInterface $item */ + /** @var \Drupal\Core\Field\FieldItemListInterface $item */ $item = $entity->get($field); $form['formatter'] = $item->view($this->settings['display_mode_edit']); if (empty($form['formatter'])) { @@ -195,7 +194,7 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { return [ '#markup' => $this->t('The field @field is missing in the @mode', [ '@field' => $field, - '@mode' => $this->form_mode, + '@mode' => $this->formMode, ]), ]; } @@ -239,7 +238,7 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { $form[$field_ajax]['widget']['#attributes'][$event] = $js; foreach (Element::children($form[$field_ajax]['widget']) as $subelement) { - if (key_exists('value', $form[$field_ajax]['widget'][$subelement])) { + if (array_key_exists('value', $form[$field_ajax]['widget'][$subelement])) { // Text fields. $form[$field_ajax]['widget'][$subelement]['value']['#attributes'][$event] = $js; } @@ -307,7 +306,7 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { return; } - $field = $this->field_name; + $field = $this->fieldName; $form_display = $this->getFormDisplay(); if (!$form_display || !$form_display->id()) { @@ -372,13 +371,13 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { /** * Loads a form display mode. * - * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface|NULL + * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface|null * Display mode. */ public function getFormDisplay() { return $this->editablefieldsHelper->getFormDisplay( $this->entity, - $this->form_mode + $this->formMode ); } @@ -387,15 +386,15 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { * * @param \Drupal\Core\Entity\EntityInterface $entity * Edited entity. - * @param $field_name + * @param string $field_name * Field name. - * @param $settings + * @param array $settings * Form mode. */ public function setDefaults(EntityInterface $entity, $field_name, array $settings) { $this->entity = $entity; - $this->field_name = $field_name; - $this->form_mode = !empty($settings['form_mode']) + $this->fieldName = $field_name; + $this->formMode = !empty($settings['form_mode']) ? $settings['form_mode'] : $this->editablefieldsHelper::DEFAULT_MODE; $this->settings = $settings; @@ -410,8 +409,8 @@ class EditableFieldsForm extends FormBase implements BaseFormIdInterface { public function prepareUniqueFormId() { return $this->editablefieldsHelper->prepareSelector( $this->entity, - $this->field_name, - $this->form_mode + $this->fieldName, + $this->formMode ); } diff --git a/src/Plugin/Field/FieldFormatter/EditableFieldsFieldFormatter.php b/src/Plugin/Field/FieldFormatter/EditableFieldsFieldFormatter.php index 65b03b7..cd38dfb 100644 --- a/src/Plugin/Field/FieldFormatter/EditableFieldsFieldFormatter.php +++ b/src/Plugin/Field/FieldFormatter/EditableFieldsFieldFormatter.php @@ -80,16 +80,16 @@ class EditableFieldsFieldFormatter extends FormatterBase { */ public static function defaultSettings() { return [ - 'form_mode' => 'default', - 'behaviour' => 'inline', - 'bypass_access' => FALSE, - 'fallback_access' => FALSE, - 'display_mode_access' => '', - 'fallback_edit' => FALSE, - 'display_mode_edit' => '', - 'fields_ajax_trigger' => '', - 'fields_ajax_trigger_event' => 'change', - ] + parent::defaultSettings(); + 'form_mode' => 'default', + 'behaviour' => 'inline', + 'bypass_access' => FALSE, + 'fallback_access' => FALSE, + 'display_mode_access' => '', + 'fallback_edit' => FALSE, + 'display_mode_edit' => '', + 'fields_ajax_trigger' => '', + 'fields_ajax_trigger_event' => 'change', + ] + parent::defaultSettings(); } /** @@ -106,110 +106,110 @@ class EditableFieldsFieldFormatter extends FormatterBase { unset($fallback_modes[$current_mode]); } return [ - 'behaviour' => [ - '#type' => 'radios', - '#title' => $this->t('Select behaviour'), - '#default_value' => $this->getSetting('behaviour') ?: 'inline', - '#options' => [ - 'inline' => $this->t('Inline form'), - 'popup' => $this->t('Form in popup'), - ], - '#description' => $this - ->t('Select formatter behaviour, read more in README.md.'), - ], - 'form_mode' => [ - '#type' => 'select', - '#title' => $this->t('Select form mode:'), - '#default_value' => $this->getSetting('form_mode'), - '#required' => 'required', - '#options' => $this->editablefieldsHelper - ->getFormModesOptions($entity_type_id), - '#description' => $this - ->t('The widget for this field in the selected form mode will be used.'), + 'behaviour' => [ + '#type' => 'radios', + '#title' => $this->t('Select behaviour'), + '#default_value' => $this->getSetting('behaviour') ?: 'inline', + '#options' => [ + 'inline' => $this->t('Inline form'), + 'popup' => $this->t('Form in popup'), ], - 'bypass_access' => [ - '#type' => 'checkbox', - '#title' => $this->t('Bypass access check'), - '#default_value' => $this->getSetting('bypass_access'), - '#description' => $this - ->t('Allows to bypass check if the user has access to update entity.'), - ], - 'fallback_access' => [ - '#type' => 'checkbox', - '#title' => $this->t('No access formatter'), - '#default_value' => $this->getSetting('fallback_access'), - '#description' => $this - ->t('Allows to select fallback formatter in case when user has no access to update entity.'), - '#states' => [ - 'visible' => [ - ':input[name$="[settings][bypass_access]"]' => ['checked' => FALSE], - ], + '#description' => $this + ->t('Select formatter behaviour, read more in README.md.'), + ], + 'form_mode' => [ + '#type' => 'select', + '#title' => $this->t('Select form mode:'), + '#default_value' => $this->getSetting('form_mode'), + '#required' => 'required', + '#options' => $this->editablefieldsHelper + ->getFormModesOptions($entity_type_id), + '#description' => $this + ->t('The widget for this field in the selected form mode will be used.'), + ], + 'bypass_access' => [ + '#type' => 'checkbox', + '#title' => $this->t('Bypass access check'), + '#default_value' => $this->getSetting('bypass_access'), + '#description' => $this + ->t('Allows to bypass check if the user has access to update entity.'), + ], + 'fallback_access' => [ + '#type' => 'checkbox', + '#title' => $this->t('No access formatter'), + '#default_value' => $this->getSetting('fallback_access'), + '#description' => $this + ->t('Allows to select fallback formatter in case when user has no access to update entity.'), + '#states' => [ + 'visible' => [ + ':input[name$="[settings][bypass_access]"]' => ['checked' => FALSE], ], ], - 'display_mode_access' => [ - '#type' => 'select', - '#title' => $this->t('Select no access display mode:'), - '#default_value' => $this->getSetting('display_mode_access'), - '#options' => $fallback_modes, - '#description' => $this - ->t('Use this formatter if user has no access to update entity.'), - '#states' => [ - 'visible' => [ - ':input[name$="[settings][fallback_access]"]' => ['checked' => TRUE], - ':input[name$="[settings][bypass_access]"]' => ['checked' => FALSE], - ], - 'required' => [ - ':input[name$="[settings][fallback_access]"]' => ['checked' => TRUE], - ':input[name$="[settings][bypass_access]"]' => ['checked' => FALSE], - ], + ], + 'display_mode_access' => [ + '#type' => 'select', + '#title' => $this->t('Select no access display mode:'), + '#default_value' => $this->getSetting('display_mode_access'), + '#options' => $fallback_modes, + '#description' => $this + ->t('Use this formatter if user has no access to update entity.'), + '#states' => [ + 'visible' => [ + ':input[name$="[settings][fallback_access]"]' => ['checked' => TRUE], + ':input[name$="[settings][bypass_access]"]' => ['checked' => FALSE], ], - ], - 'fallback_edit' => [ - '#type' => 'checkbox', - '#title' => $this->t('Use fallback formatter'), - '#default_value' => $this->getSetting('fallback_edit'), - '#description' => $this - ->t('The widget for this field in the selected form mode will be used.'), - '#states' => [ - 'checked' => [ - [':input[name$="[settings][behaviour]"]' => ['value' => 'popup']], - ], - 'required' => [ - [':input[name$="[settings][behaviour]"]' => ['value' => 'popup']], - ], + 'required' => [ + ':input[name$="[settings][fallback_access]"]' => ['checked' => TRUE], + ':input[name$="[settings][bypass_access]"]' => ['checked' => FALSE], ], ], - 'display_mode_edit' => [ - '#type' => 'select', - '#title' => $this->t('Select fallback display mode:'), - '#default_value' => $this->getSetting('display_mode_edit'), - '#options' => $fallback_modes, - '#description' => $this - ->t('Use this formatter before user clicks "edit" to get the widget/popup.'), - '#states' => [ - 'visible' => [ - [':input[name$="[settings][fallback_edit]"]' => ['checked' => TRUE]], - [':input[name$="[settings][behaviour]"]' => ['value' => 'popup']], - ], - 'required' => [ - [':input[name$="[settings][fallback_edit]"]' => ['checked' => TRUE]], - [':input[name$="[settings][behaviour]"]' => ['value' => 'popup']], - ], + ], + 'fallback_edit' => [ + '#type' => 'checkbox', + '#title' => $this->t('Use fallback formatter'), + '#default_value' => $this->getSetting('fallback_edit'), + '#description' => $this + ->t('The widget for this field in the selected form mode will be used.'), + '#states' => [ + 'checked' => [ + [':input[name$="[settings][behaviour]"]' => ['value' => 'popup']], + ], + 'required' => [ + [':input[name$="[settings][behaviour]"]' => ['value' => 'popup']], ], ], - 'fields_ajax_trigger' => [ - '#type' => 'textfield', - '#title' => t('Fields that trigger an ajax submit when they change (autosave)'), - '#description' => $this->t('A comma separated list of fields. When this is configured the update button will be hidden.'), - '#default_value' => $this->getSetting('fields_ajax_trigger'), - ], - 'fields_ajax_trigger_event' => [ - '#type' => 'textfield', - '#title' => t('Event that will trigger an ajax submit for the fields above'), - '#description' => $this->t('Tipically "change" for select fields but for text fields you might want to use "blur"'), - '#default_value' => $this->getSetting('fields_ajax_trigger_event'), + ], + 'display_mode_edit' => [ + '#type' => 'select', + '#title' => $this->t('Select fallback display mode:'), + '#default_value' => $this->getSetting('display_mode_edit'), + '#options' => $fallback_modes, + '#description' => $this + ->t('Use this formatter before user clicks "edit" to get the widget/popup.'), + '#states' => [ + 'visible' => [ + [':input[name$="[settings][fallback_edit]"]' => ['checked' => TRUE]], + [':input[name$="[settings][behaviour]"]' => ['value' => 'popup']], + ], + 'required' => [ + [':input[name$="[settings][fallback_edit]"]' => ['checked' => TRUE]], + [':input[name$="[settings][behaviour]"]' => ['value' => 'popup']], + ], ], - ] + parent::settingsForm($form, $form_state); + ], + 'fields_ajax_trigger' => [ + '#type' => 'textfield', + '#title' => t('Fields that trigger an ajax submit when they change (autosave)'), + '#description' => $this->t('A comma separated list of fields. When this is configured the update button will be hidden.'), + '#default_value' => $this->getSetting('fields_ajax_trigger'), + ], + 'fields_ajax_trigger_event' => [ + '#type' => 'textfield', + '#title' => t('Event that will trigger an ajax submit for the fields above'), + '#description' => $this->t('Typically "change" for select fields but for text fields you might want to use "blur"'), + '#default_value' => $this->getSetting('fields_ajax_trigger_event'), + ], + ] + parent::settingsForm($form, $form_state); } /** @@ -309,12 +309,12 @@ class EditableFieldsFieldFormatter extends FormatterBase { 'behaviour' => $settings['behaviour'] ?? 'inline', 'bypass_access' => !empty($settings['bypass_access']), 'fallback_access' => !empty($settings['fallback_access']) - && !empty($settings['display_mode_access']), + && !empty($settings['display_mode_access']), 'display_mode_access' => !empty($settings['display_mode_access']) ? $settings['display_mode_access'] : $default, 'fallback_edit' => !empty($settings['fallback_edit']) - && !empty($settings['display_mode_edit']), + && !empty($settings['display_mode_edit']), 'display_mode_edit' => !empty($settings['display_mode_edit']) ? $settings['display_mode_edit'] : $default, diff --git a/src/services/EditableFieldsHelper.php b/src/services/EditableFieldsHelper.php index 8dff8f9..b0a4b54 100644 --- a/src/services/EditableFieldsHelper.php +++ b/src/services/EditableFieldsHelper.php @@ -3,7 +3,6 @@ namespace Drupal\editablefields\services; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\DependencyInjection\ClassResolverInterface; @@ -122,7 +121,7 @@ class EditableFieldsHelper { * Entity object. * * @return bool - * TRUE if the user can use "editablefields" formatret. + * TRUE if the user can use "editablefields" formatter. */ public function checkAccess(EntityInterface $entity) { $can_edit = $entity->access('update'); @@ -167,10 +166,11 @@ class EditableFieldsHelper { * * @param \Drupal\Core\Entity\EntityInterface $entity * Entity object. - * @param $form_mode + * @param string $form_mode * Form mode. * - * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface|NULL + * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface|null + * Form display. */ public function getFormDisplay(EntityInterface $entity, $form_mode) { return $this->entityDisplayRepository->getFormDisplay( @@ -193,7 +193,6 @@ class EditableFieldsHelper { return $this->entityDisplayRepository->getFormModeOptions($entity_type_id); } - /** * Helper method to prepare the list of the view modes. * -- GitLab From dafeb7ae05cd912e5c8a3f80d60c8bc958da578a Mon Sep 17 00:00:00 2001 From: Artem Konotopchyk Date: Mon, 29 Sep 2025 15:36:27 +0300 Subject: [PATCH 2/2] Issue #3547982: make OPT_IN_TEST_MAX_PHP equals 1 --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 795df11..41fb262 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,7 +28,7 @@ variables: OPT_IN_TEST_PREVIOUS_MINOR: 1 OPT_IN_TEST_NEXT_MINOR: 1 OPT_IN_TEST_NEXT_MAJOR: 1 - OPT_IN_TEST_MAX_PHP: 0 + OPT_IN_TEST_MAX_PHP: 1 RUN_JOB_UPGRADE_STATUS: 1 - # Do not mark as an error: `behaviour` (british english), `subelement` (variable name), + # Do not mark as an error: `behaviour` (british english), `subelement` (variable name), _CSPELL_WORDS: 'behaviour,behaviours,subelement' -- GitLab