diff --git a/README.md b/README.md index c6c22971b1c14f2a2eb37c2fa6c88ab1c7fc4899..7494ae939d5155f80ab45f1ef36f512f7b34d605 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 3a9fcdc7717ad92e306c5555f66105f2821a6e55..c0a58d77140cc47315c34a555f9da261c0404357 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 fcb428bd9d1a8d35d5d38857de5e72679f26c8a5..2b1e631b47f83b7371321991d70b65f10fae8ffe 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 609a6b910596f593372663cd49c6742b135b82c7..933ad327f22f9fbc5bc9d13d6a436f3c9894c813 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 fef46993a0db2b0bf6499424b14e40de1fd9e1cd..afa63cef14fae597740876b07371560e32edfddb 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 ac94656d43f1b7d5ff357bf5e2d7bfdc68f0d38c..85a263114393ca6c76667f75ece5760d6948973b 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 e4646023dc60e74376f5964c58d77998e91381f5..841177bc4d5f6503ede6059489582ec50876c120 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 17c6cae129897598ce11dcee29db88df134bc990..19ae6e7d67b2dc57e752b857423e4d173d3fb1b4 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 20885e8b97d78b87d6a66e56ec127bf9f870902d..fb9e1fdad63de5cff45cac6a48330bb8d8266876 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 d2e8a2008238bf701834f2a354e0543b1f974cb7..37622273bf7d355d7d32054dd17d9baa6de903ec 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 a6fec3fa61cad8ec8a964d4f580a2075072d780f..905d500a89de5d085aceb4e4ff78759deedab9b3 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 260d456daea2d1d3277f1fe59cc6f0c7e15b76a1..5c8df8f9206f97824236e9e1e6ee0ab4f98dbb0b 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. */