From c9aa146fe4b4dfb4c10cfee88e507f13bdd8aa21 Mon Sep 17 00:00:00 2001 From: Urvashi Vora <48454-urvashivora@users.noreply.drupalcode.org> Date: Thu, 25 May 2023 18:18:55 +0300 Subject: [PATCH] Issue #3362087 by urvashi_vora, apaderno: Fix the issues reported by phpcs --- README.md | 12 ++++++++---- inline_entity_form.api.php | 8 ++++---- inline_entity_form.module | 6 +++--- src/Element/InlineEntityForm.php | 5 +++-- src/Form/ConfigEntityInlineForm.php | 2 +- src/Form/NodeInlineForm.php | 2 -- src/MigrationHelper.php | 4 ++-- .../Field/FieldWidget/InlineEntityFormBase.php | 8 ++++---- .../Field/FieldWidget/InlineEntityFormComplex.php | 4 ++++ src/Tests/ContentModerationTranslationTest.php | 8 ++++---- src/WidgetSubmit.php | 5 +++-- .../inline_entity_form_test.module | 2 +- 12 files changed, 37 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index c6c22971..7494ae93 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ -Provides a widget for inline management (creation, modification, removal) of referenced entities. -The primary use case is the parent -> children one (product display -> products, order -> line items, etc.), +Provides a widget for inline management (creation, modification, removal) of +referenced entities. +The primary use case is the parent -> children one (product display -> products, +order -> line items, etc.), where the child entities are never managed outside the parent form. Existing entities can also be referenced. -Supports commerce_product_reference, commerce_line_item_reference and entityreference fields. -Requires integration code to be provided for each entity type that can be referenced. +Supports commerce_product_reference, commerce_line_item_reference and +entityreference fields. +Requires integration code to be provided for each entity type that can be +referenced. Supports the commerce_product (including Commerce AutoSKU integraton), commerce_line_item, node, taxonomy_term entity types out of the box. diff --git a/inline_entity_form.api.php b/inline_entity_form.api.php index 3a9fcdc7..c0a58d77 100644 --- a/inline_entity_form.api.php +++ b/inline_entity_form.api.php @@ -10,10 +10,10 @@ * * @param array $entity_form * Nested array of form elements that comprise the entity form. - * @param $form_state + * @param FormStateInterface $form_state * The form state of the parent form. */ -function hook_inline_entity_form_entity_form_alter(array &$entity_form, \Drupal\Core\Form\FormStateInterface &$form_state) { +function hook_inline_entity_form_entity_form_alter(array &$entity_form, FormStateInterface &$form_state) { if ($entity_form['#entity_type'] == 'commerce_line_item') { $entity_form['quantity']['#description'] = t('New quantity description.'); } @@ -27,10 +27,10 @@ function hook_inline_entity_form_entity_form_alter(array &$entity_form, \Drupal\ * * @param array $reference_form * Nested array of form elements that comprise the reference form. - * @param $form_state + * @param FormStateInterface $form_state * The form state of the parent form. */ -function hook_inline_entity_form_reference_form_alter(array &$reference_form, \Drupal\Core\Form\FormStateInterface &$form_state) { +function hook_inline_entity_form_reference_form_alter(array &$reference_form, FormStateInterface &$form_state) { $reference_form['entity_id']['#description'] = t('New autocomplete description'); } diff --git a/inline_entity_form.module b/inline_entity_form.module index fcb428bd..2b1e631b 100644 --- a/inline_entity_form.module +++ b/inline_entity_form.module @@ -503,12 +503,12 @@ function inline_entity_form_migration_plugins_alter(array &$migrations) { /** * Change text button by type of bundle. * - * @param $form + * @param array $form * The complete parent form. - * @param $form_state + * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state of the parent form. */ -function inline_entity_form_change_bundle_form($form, FormStateInterface $form_state) { +function inline_entity_form_change_bundle_form(array $form, FormStateInterface $form_state) { $element = inline_entity_form_get_element($form, $form_state); $elements = $form_state->getTriggeringElement(); diff --git a/src/Element/InlineEntityForm.php b/src/Element/InlineEntityForm.php index 609a6b91..933ad327 100644 --- a/src/Element/InlineEntityForm.php +++ b/src/Element/InlineEntityForm.php @@ -177,8 +177,9 @@ class InlineEntityForm extends RenderElement { * The entity form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. - * - * @return Drupal\Core\Entity\EntityInterface\null + * + * @return Drupal\Core\Entity\EntityInterface|null + * Returns saved entity if true, else null. */ public static function submitEntityForm(array &$entity_form, FormStateInterface $form_state) { $inline_form_handler = static::getInlineFormHandler($entity_form['#entity_type']); diff --git a/src/Form/ConfigEntityInlineForm.php b/src/Form/ConfigEntityInlineForm.php index fef46993..afa63cef 100644 --- a/src/Form/ConfigEntityInlineForm.php +++ b/src/Form/ConfigEntityInlineForm.php @@ -64,7 +64,7 @@ class ConfigEntityInlineForm extends EntityInlineForm { $form_object = $this->getFormObject($entity, $entity_form['#form_mode']); $form_object->validateForm($entity_form, $this->getSubformState($entity_form, $form_state)); - foreach ($form_state->getErrors() as $name => $message) { + foreach ($form_state->getErrors() as $message) { // $name may be unknown in $form_state and // $form_state->setErrorByName($name, $message) may suppress the error // message. diff --git a/src/Form/NodeInlineForm.php b/src/Form/NodeInlineForm.php index ac94656d..85a26311 100644 --- a/src/Form/NodeInlineForm.php +++ b/src/Form/NodeInlineForm.php @@ -3,8 +3,6 @@ namespace Drupal\inline_entity_form\Form; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Entity\EntityInterface; /** * Node inline form handler. diff --git a/src/MigrationHelper.php b/src/MigrationHelper.php index e4646023..841177bc 100644 --- a/src/MigrationHelper.php +++ b/src/MigrationHelper.php @@ -165,8 +165,8 @@ class MigrationHelper { $merged_values = array_replace_recursive($group_value, $migration_value); $migration[$key] = $merged_values; } - // Where the group provides a value the migration doesn't, use the group - // value. + // Where the group provides a value the migration doesn't, + // use the group value. elseif (is_null($migration_value)) { $migration[$key] = $group_value; } diff --git a/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php b/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php index 17c6cae1..19ae6e7d 100644 --- a/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php +++ b/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php @@ -277,7 +277,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto $labels = $this->getSetting('labels'); $element['labels']['label_singular_' . $bundle] = [ '#type' => 'textfield', - '#title' => $this->t('Singular label ' . $bundle), + '#title' => $this->t('Singular label @bundle', ['@bundle' => $bundle]), '#default_value' => ($labels ? $labels['label_singular_' . $bundle] : NULL), '#states' => [ 'visible' => [ @@ -287,7 +287,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto ]; $element['labels']['label_plural_' . $bundle] = [ '#type' => 'textfield', - '#title' => $this->t('Plural label ' . $bundle), + '#title' => $this->t('Plural label @bundle', ['@bundle' => $bundle]), '#default_value' => ($labels ? $labels['label_plural_' . $bundle] : NULL), '#states' => [ 'visible' => [ @@ -304,7 +304,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto 'visible' => [ ':input[name="' . $states_prefix . '[override_labels]"]' => ['checked' => TRUE], 'and', - ':input[name="' . $states_prefix . '[config_labels_button]"]' => ['!value' => 'complex_label'], + ':input[name="' . $states_prefix . '[config_labels_button]"]' => [['!value' => 'complex_label']], ], ], ]; @@ -479,7 +479,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto } /** - * + * Checks if the entity is opened from the query parameter in the form state. */ public static function entityIsOpenFromQuery(ContentEntityInterface $entity, FormStateInterface $form_state) { $query = \Drupal::request()->query; diff --git a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php index 20885e8b..fb9e1fda 100644 --- a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php +++ b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php @@ -1263,7 +1263,10 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF } /** + * Retrieves the labels for the entity type. + * * @return array|\Drupal\Core\Entity\EntityTypeInterface + * An array with entity type labels or labels from parent class. */ protected function getEntityTypeLabels() { if ($this->getSetting('override_labels')) { @@ -1282,6 +1285,7 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF * Generate unique wrapper id for IEF element. * * @param string $ief_id + * The ID of the IEF element. */ public static function getWrapperId($ief_id) { static $ids = []; diff --git a/src/Tests/ContentModerationTranslationTest.php b/src/Tests/ContentModerationTranslationTest.php index d2e8a200..37622273 100644 --- a/src/Tests/ContentModerationTranslationTest.php +++ b/src/Tests/ContentModerationTranslationTest.php @@ -58,7 +58,7 @@ class ContentModerationTranslationTest extends InlineEntityFormTestBase { $edit['settings[node][' . $node_type . '][translatable]'] = TRUE; $edit['settings[node][' . $node_type . '][settings][language][language_alterable]'] = TRUE; } - $this->submitForm('admin/config/regional/content-language', $edit, t('Save configuration')); + $this->submitForm('admin/config/regional/content-language', $edit, $this->t('Save configuration')); // Allow referencing existing entities. $form_display_storage = $this->container->get('entity_type.manager')->getStorage('entity_form_display'); @@ -111,7 +111,7 @@ class ContentModerationTranslationTest extends InlineEntityFormTestBase { 'title[0][value]' => 'A node', 'langcode[0][value]' => 'en', ]; - $this->submitForm(NULL, $edit, t('Save')); + $this->submitForm(NULL, $edit, $this->t('Save')); $this->assertSession()->statusCodeEquals(200, 'Saving the parent entity was successful.'); // Both inline nodes should now be in English. @@ -126,7 +126,7 @@ class ContentModerationTranslationTest extends InlineEntityFormTestBase { $edit = [ 'langcode[0][value]' => 'de', ]; - $this->submitForm(NULL, $edit, t('Save')); + $this->submitForm(NULL, $edit, $this->t('Save')); $this->assertSession()->statusCodeEquals(200, 'Saving the parent entity was successful.'); // Both inline nodes should now be in German. @@ -166,7 +166,7 @@ class ContentModerationTranslationTest extends InlineEntityFormTestBase { ]; $this->submitForm(NULL, $edit, $this->getButtonName('//input[@type="submit" and @value="Update node" and @data-drupal-selector="edit-multi-form-inline-entity-form-entities-1-form-actions-ief-edit-save"]')); - $this->submitForm(NULL, [], t('Save (this translation)')); + $this->submitForm(NULL, [], $this->t('Save (this translation)')); $this->assertSession()->statusCodeEquals(200, 'Saving the parent entity was successful.'); // Load using the original titles, confirming they haven't changed. diff --git a/src/WidgetSubmit.php b/src/WidgetSubmit.php index a6fec3fa..905d500a 100644 --- a/src/WidgetSubmit.php +++ b/src/WidgetSubmit.php @@ -58,13 +58,14 @@ class WidgetSubmit { $handler->save($entity); $referenceUpgrader->registerEntity($entity); $entity_item['needs_save'] = FALSE; - \Drupal::moduleHandler()->invokeAll('inline_entity_form_entity_save', [&$form_state, $entity, $is_new]); + \Drupal::moduleHandler()->invokeAll('inline_entity_form_entity_save', + [&$form_state, $entity, $is_new]); } } /** @var \Drupal\Core\Entity\ContentEntityInterface $entities */ foreach ($widget_state['delete'] as $entity) { - \Drupal::moduleHandler()->invokeAll('inline_entity_form_entity_delete', [&$form_state, $entity]); + \Drupal::moduleHandler()->invokeAll('inline_entity_form_entity_delete',[&$form_state, $entity]); $entity->delete(); } unset($widget_state['delete']); diff --git a/tests/modules/inline_entity_form_test/inline_entity_form_test.module b/tests/modules/inline_entity_form_test/inline_entity_form_test.module index 260d456d..5c8df8f9 100644 --- a/tests/modules/inline_entity_form_test/inline_entity_form_test.module +++ b/tests/modules/inline_entity_form_test/inline_entity_form_test.module @@ -10,7 +10,7 @@ use Drupal\Core\Ajax\HtmlCommand; use Drupal\Core\Form\FormStateInterface; /** - * Implements hook_form_BASE_FORM_ID_alter for node_ief_simple_single_form. + * Implements hook_form_BASE_FORM_ID_alter() for node_ief_simple_single_form. * * Adds an element and a button to update the element via AJAX. */ -- GitLab