diff --git a/composer.json b/composer.json index a40e62df8829452857a837f47bcae9f8f24bf7aa..0214b68266f2c534762c187087c1cbaf7c455993 100644 --- a/composer.json +++ b/composer.json @@ -127,7 +127,7 @@ "drupal/google_analytics": "^4.0", "drupal/google_tag": "1.5", "drupal/honeypot": "2.1.2", - "drupal/inline_entity_form": "1.0-rc9", + "drupal/inline_entity_form": "1.0-rc14", "drupal/libraries": "3.0-beta1", "drupal/link_attributes": "1.11", "drupal/linkit": "5.0-beta13", @@ -295,9 +295,6 @@ "drupal/honeypot": { "2811189": "https://www.drupal.org/files/issues/2022-05-25/honeypot-field_weight-2811189-27_0.patch" }, - "drupal/inline_entity_form": { - "3208279": "https://www.drupal.org/files/issues/2021-05-08/inline_entity_form-n3208279-13.patch" - }, "drupal/linkit": { "2712951": "https://www.drupal.org/files/issues/2021-04-07/linkit-for-link-field-2712951-216.patch" }, diff --git a/composer.lock b/composer.lock index c38b50fc2076f3b35edc319b19b2a05703d54c09..8d7d4c861c629b1ff3b56fa00d6ec9491646bee8 100644 --- a/composer.lock +++ b/composer.lock @@ -4751,20 +4751,20 @@ }, { "name": "drupal/inline_entity_form", - "version": "1.0.0-rc9", + "version": "1.0.0-rc14", "source": { "type": "git", "url": "https://git.drupalcode.org/project/inline_entity_form.git", - "reference": "8.x-1.0-rc9" + "reference": "8.x-1.0-rc14" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/inline_entity_form-8.x-1.0-rc9.zip", - "reference": "8.x-1.0-rc9", - "shasum": "78953103a9c6e4e44bc877820a35f39913ea4559" + "url": "https://ftp.drupal.org/files/projects/inline_entity_form-8.x-1.0-rc14.zip", + "reference": "8.x-1.0-rc14", + "shasum": "2c9efd73332acfba43fe9b29e78e508ddc9d3664" }, "require": { - "drupal/core": "^8.8 || ^9", + "drupal/core": "^8.8 || ^9 || ^10", "php": ">=7.1" }, "require-dev": { @@ -4773,8 +4773,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-1.0-rc9", - "datestamp": "1618174486", + "version": "8.x-1.0-rc14", + "datestamp": "1663701306", "security-coverage": { "status": "not-covered", "message": "RC releases are not covered by Drupal security advisories." diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 3419ab04337d2341de33d5fba1c95412daa01b73..302d9f0e46ccd4bc296658f9aa56ad8dadaa5617 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -4913,21 +4913,21 @@ }, { "name": "drupal/inline_entity_form", - "version": "1.0.0-rc9", - "version_normalized": "1.0.0.0-RC9", + "version": "1.0.0-rc14", + "version_normalized": "1.0.0.0-RC14", "source": { "type": "git", "url": "https://git.drupalcode.org/project/inline_entity_form.git", - "reference": "8.x-1.0-rc9" + "reference": "8.x-1.0-rc14" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/inline_entity_form-8.x-1.0-rc9.zip", - "reference": "8.x-1.0-rc9", - "shasum": "78953103a9c6e4e44bc877820a35f39913ea4559" + "url": "https://ftp.drupal.org/files/projects/inline_entity_form-8.x-1.0-rc14.zip", + "reference": "8.x-1.0-rc14", + "shasum": "2c9efd73332acfba43fe9b29e78e508ddc9d3664" }, "require": { - "drupal/core": "^8.8 || ^9", + "drupal/core": "^8.8 || ^9 || ^10", "php": ">=7.1" }, "require-dev": { @@ -4936,16 +4936,14 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-1.0-rc9", - "datestamp": "1618174486", + "version": "8.x-1.0-rc14", + "datestamp": "1663701306", "security-coverage": { "status": "not-covered", "message": "RC releases are not covered by Drupal security advisories." } }, - "patches_applied": { - "3208279": "https://www.drupal.org/files/issues/2021-05-08/inline_entity_form-n3208279-13.patch" - } + "patches_applied": [] }, "installation-source": "dist", "notification-url": "https://packages.drupal.org/8/downloads", @@ -4957,6 +4955,10 @@ "name": "bojanz", "homepage": "https://www.drupal.org/user/86106" }, + { + "name": "Centarro", + "homepage": "https://www.drupal.org/user/3661446" + }, { "name": "dawehner", "homepage": "https://www.drupal.org/user/99340" @@ -4981,6 +4983,10 @@ "name": "oknate", "homepage": "https://www.drupal.org/user/471638" }, + { + "name": "ram4nd", + "homepage": "https://www.drupal.org/user/601534" + }, { "name": "rszrama", "homepage": "https://www.drupal.org/user/49344" diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index c59295b1959885e252b3026858890764a3cc3f9f..6c57d2d6646598ac75f51cb524b289c262e166b5 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -857,9 +857,9 @@ 'dev_requirement' => false, ), 'drupal/inline_entity_form' => array( - 'pretty_version' => '1.0.0-rc9', - 'version' => '1.0.0.0-RC9', - 'reference' => '8.x-1.0-rc9', + 'pretty_version' => '1.0.0-rc14', + 'version' => '1.0.0.0-RC14', + 'reference' => '8.x-1.0-rc14', 'type' => 'drupal-module', 'install_path' => __DIR__ . '/../../web/modules/inline_entity_form', 'aliases' => array(), diff --git a/web/modules/inline_entity_form/.gitignore b/web/modules/inline_entity_form/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4a622583de05578097f472ebee4cc30040ef9f2d --- /dev/null +++ b/web/modules/inline_entity_form/.gitignore @@ -0,0 +1,12 @@ +/.idea/ +/vendor/ +/composer.lock +/composer.spoons.json +/composer.spoons.lock +/web/ +/.env +/.envrc +/.envrc.local +/.composer-plugin.env +/.editorconfig +/.gitattributes diff --git a/web/modules/inline_entity_form/composer.json b/web/modules/inline_entity_form/composer.json index b096f37e6978b0a16990143aeb09e3018f66aa72..5f08138398aff7ef001065c070bed218d39d605b 100644 --- a/web/modules/inline_entity_form/composer.json +++ b/web/modules/inline_entity_form/composer.json @@ -6,7 +6,7 @@ "minimum-stability": "dev", "require": { "php": ">=7.1", - "drupal/core": "^8.8 || ^9" + "drupal/core": "^8.8 || ^9 || ^10" }, "require-dev": { "drupal/entity_reference_revisions": "^1.0" diff --git a/web/modules/inline_entity_form/inline_entity_form.api.php b/web/modules/inline_entity_form/inline_entity_form.api.php index 4e310ec33ec805b54467bfde98a14827dca3e18c..ae3d5672a9363e4631440a266921b1a8d87c55e6 100644 --- a/web/modules/inline_entity_form/inline_entity_form.api.php +++ b/web/modules/inline_entity_form/inline_entity_form.api.php @@ -23,7 +23,7 @@ function hook_inline_entity_form_entity_form_alter(array &$entity_form, FormStat * Perform alterations before the reference form is included in the IEF widget. * * The reference form is used to add existing entities through an autocomplete - * field + * field. * * @param array $reference_form * Nested array of form elements that comprise the reference form. diff --git a/web/modules/inline_entity_form/inline_entity_form.info.yml b/web/modules/inline_entity_form/inline_entity_form.info.yml index 150d51db9bdfb93978a1214bfb6336cdc551290a..deb9b63d0dec69d6e4c84f70aba0bab1e0c4e638 100644 --- a/web/modules/inline_entity_form/inline_entity_form.info.yml +++ b/web/modules/inline_entity_form/inline_entity_form.info.yml @@ -2,10 +2,10 @@ name: Inline Entity Form description: "Provides a widget for inline management (creation, modification, removal) of referenced entities. " type: module package: Fields -core_version_requirement: ^8.8 || ^9 +core_version_requirement: ^8.8 || ^9 || ^10 php: 7.1 -# Information added by Drupal.org packaging script on 2021-04-11 -version: '8.x-1.0-rc9' +# Information added by Drupal.org packaging script on 2022-09-20 +version: '8.x-1.0-rc14' project: 'inline_entity_form' -datestamp: 1618174489 +datestamp: 1663701307 diff --git a/web/modules/inline_entity_form/inline_entity_form.module b/web/modules/inline_entity_form/inline_entity_form.module index 63e26c42ba8cd73038c90ef28674604052879c14..8f6b69d90fb978e6e5759b70b5a55b6bd70beee4 100644 --- a/web/modules/inline_entity_form/inline_entity_form.module +++ b/web/modules/inline_entity_form/inline_entity_form.module @@ -2,6 +2,8 @@ /** * @file + * The inline entity form module. + * * Provides a widget for inline management (creation, modification, removal) of * referenced entities. The primary use case is the parent -> children one * (for example, order -> line items), where the child entities are never @@ -70,7 +72,7 @@ function inline_entity_form_theme() { * @return array * The form array containing the embedded form. */ -function inline_entity_form_reference_form($reference_form, FormStateInterface &$form_state) { +function inline_entity_form_reference_form(array $reference_form, FormStateInterface &$form_state) { $labels = $reference_form['#ief_labels']; $ief_id = $reference_form['#ief_id']; /** @var \Drupal\field\Entity\FieldConfig $instance */ @@ -93,7 +95,7 @@ function inline_entity_form_reference_form($reference_form, FormStateInterface & '#required' => TRUE, '#maxlength' => 255, ]; - // Add the actions + // Add the actions. $reference_form['actions'] = [ '#type' => 'container', '#weight' => 100, @@ -119,7 +121,12 @@ function inline_entity_form_reference_form($reference_form, FormStateInterface & 'callback' => 'inline_entity_form_get_element', 'wrapper' => 'inline-entity-form-' . $reference_form['#ief_id'], ], - '#submit' => [['\Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex', 'closeForm']], + '#submit' => [ + [ + '\Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex', + 'closeForm', + ], + ], ]; $reference_form['#element_validate'][] = 'inline_entity_form_reference_form_validate'; @@ -139,7 +146,7 @@ function inline_entity_form_reference_form($reference_form, FormStateInterface & * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state of the parent form. */ -function inline_entity_form_reference_form_validate(&$reference_form, FormStateInterface $form_state) { +function inline_entity_form_reference_form_validate(array &$reference_form, FormStateInterface $form_state) { $form_values = NestedArray::getValue($form_state->getValues(), $reference_form['#parents']); if (empty($form_values['entity_id'])) { // The entity_id element is required, the value is empty only if @@ -153,7 +160,7 @@ function inline_entity_form_reference_form_validate(&$reference_form, FormStateI // Check if the entity is already referenced by the field. if (!empty($entity)) { - foreach ($form_state->get(['inline_entity_form', $ief_id, 'entities']) as $key => $value) { + foreach ($form_state->get(['inline_entity_form', $ief_id, 'entities']) as $value) { if ($value['entity'] && $value['entity']->id() == $entity->id()) { $form_state->setError($reference_form['entity_id'], t('The selected @label has already been added.', ['@label' => $labels['singular']])); break; @@ -172,7 +179,7 @@ function inline_entity_form_reference_form_validate(&$reference_form, FormStateI * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state of the parent form. */ -function inline_entity_form_reference_form_submit($reference_form, FormStateInterface $form_state) { +function inline_entity_form_reference_form_submit(array $reference_form, FormStateInterface $form_state) { $ief_id = $reference_form['#ief_id']; $form_values = NestedArray::getValue($form_state->getValues(), $reference_form['#parents']); $storage = \Drupal::entityTypeManager()->getStorage($reference_form['#entity_type']); @@ -198,12 +205,12 @@ function inline_entity_form_reference_form_submit($reference_form, FormStateInte * * The form is shown below the entity table, at the bottom of the widget. * - * @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_open_form($form, FormStateInterface $form_state) { +function inline_entity_form_open_form(array $form, FormStateInterface $form_state) { $element = inline_entity_form_get_element($form, $form_state); $ief_id = $element['#ief_id']; $form_state->setRebuild(); @@ -224,12 +231,12 @@ function inline_entity_form_open_form($form, FormStateInterface $form_state) { /** * Button #submit callback: Cleans up form state for a closed entity form. * - * @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_cleanup_form_state($form, FormStateInterface $form_state) { +function inline_entity_form_cleanup_form_state(array $form, FormStateInterface $form_state) { $element = inline_entity_form_get_element($form, $form_state); EntityInlineForm::submitCleanFormState($element['form']['inline_entity_form'], $form_state); } @@ -240,12 +247,12 @@ function inline_entity_form_cleanup_form_state($form, FormStateInterface $form_s * The row is identified by #ief_row_delta stored on the triggering * element. * - * @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_open_row_form($form, FormStateInterface $form_state) { +function inline_entity_form_open_row_form(array $form, FormStateInterface $form_state) { $element = inline_entity_form_get_element($form, $form_state); $ief_id = $element['#ief_id']; $delta = $form_state->getTriggeringElement()['#ief_row_delta']; @@ -254,18 +261,17 @@ function inline_entity_form_open_row_form($form, FormStateInterface $form_state) $form_state->set(['inline_entity_form', $ief_id, 'entities', $delta, 'form'], $form_state->getTriggeringElement()['#ief_row_form']); } - /** * Closes all open IEF forms. * * Recurses and closes open forms in nested IEF widgets as well. * - * @param $elements + * @param array $elements * An array of form elements containing entity forms. - * @param $form_state + * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state of the parent form. */ -function inline_entity_form_close_all_forms($elements, FormStateInterface $form_state) { +function inline_entity_form_close_all_forms(array $elements, FormStateInterface $form_state) { // Recurse through all children. foreach (Element::children($elements) as $key) { if (!empty($elements[$key])) { @@ -289,12 +295,12 @@ function inline_entity_form_close_all_forms($elements, FormStateInterface $form_ /** * Button #submit callback: Cleans up form state for a closed entity row form. * - * @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_cleanup_row_form_state($form, FormStateInterface $form_state) { +function inline_entity_form_cleanup_row_form_state(array $form, FormStateInterface $form_state) { $element = inline_entity_form_get_element($form, $form_state); $delta = $form_state->getTriggeringElement()['#ief_row_delta']; $entity_form = $element['entities'][$delta]['form']['inline_entity_form']; @@ -341,12 +347,18 @@ function template_preprocess_inline_entity_form_entity_table(array &$variables) $header = []; if ($has_tabledrag) { $header[] = ['data' => '', 'class' => ['ief-tabledrag-header']]; - $header[] = ['data' => t('Sort order'), 'class' => ['ief-sort-order-header']]; + $header[] = [ + 'data' => t('Sort order'), + 'class' => ['ief-sort-order-header'], + ]; } // Add header columns for each field. $first = TRUE; foreach ($fields as $field_name => $field) { - $column = ['data' => $field['label'], 'class' => ['inline-entity-form-' . $entity_type . '-' . $field_name]]; + $column = [ + 'data' => $field['label'], + 'class' => ['inline-entity-form-' . $entity_type . '-' . $field_name], + ]; // The first column gets a special class. if ($first) { $column['class'][] = 'ief-first-column-header'; @@ -364,7 +376,10 @@ function template_preprocess_inline_entity_form_entity_table(array &$variables) $row_classes = ['ief-row-entity']; $cells = []; if ($has_tabledrag) { - $cells[] = ['data' => ['#plain_text' => ''], '#wrapper_attributes' => ['class' => ['ief-tabledrag-handle']]]; + $cells[] = [ + 'data' => ['#plain_text' => ''], + '#wrapper_attributes' => ['class' => ['ief-tabledrag-handle']], + ]; $cells[] = ['data' => $form[$key]['delta']]; $row_classes[] = 'draggable'; } @@ -394,10 +409,11 @@ function template_preprocess_inline_entity_form_entity_table(array &$variables) $arguments = array_merge($arguments, $field['callback_arguments']); } - $data = call_user_func_array($field['callback'], $arguments); + $data = call_user_func_array($field['callback'], array_values($arguments)); - // Backward compatibility for callbacks that just provide a string not an array. - if(!is_array($data)) { + // Backward compatibility for callbacks that just provide a string not + // an array. + if (!is_array($data)) { $data = ['#markup' => $data]; } } @@ -419,7 +435,13 @@ function template_preprocess_inline_entity_form_entity_table(array &$variables) if (!empty($form[$key]['form'])) { $row = []; $row[] = $form[$key]['form'] + ['#wrapper_attributes' => ['colspan' => count($fields) + 1]]; - $rows[] = $row + ['#attributes' => ['class' => ['ief-row-form'], 'no_striping' => TRUE]]; + $rows[] = $row + [ + '#attributes' => + [ + 'class' => ['ief-row-form'], + 'no_striping' => TRUE, + ], + ]; } } @@ -447,7 +469,6 @@ function template_preprocess_inline_entity_form_entity_table(array &$variables) } } - /** * Implements hook_migrate_prepare_row(). */ @@ -455,3 +476,11 @@ function inline_entity_form_migrate_prepare_row(Row $row, MigrateSourceInterface \Drupal::classResolver(MigrationHelper::class) ->alterRow($row, $source, $migration); } + +/** + * Implements hook_migration_plugins_alter(). + */ +function inline_entity_form_migration_plugins_alter(array &$migrations) { + \Drupal::classResolver(MigrationHelper::class) + ->alterPlugins($migrations); +} diff --git a/web/modules/inline_entity_form/inline_entity_form.module.rej b/web/modules/inline_entity_form/inline_entity_form.module.rej new file mode 100644 index 0000000000000000000000000000000000000000..a3dd44adaac7a24adbbd5b3c4287cccc4b417cd2 --- /dev/null +++ b/web/modules/inline_entity_form/inline_entity_form.module.rej @@ -0,0 +1,18 @@ +*************** +*** 484,495 **** + \Drupal::classResolver(MigrationHelper::class) + ->alterRow($row, $source, $migration); + } +- +- +- /** +- * Implements hook_migration_plugins_alter(). +- */ +- function inline_entity_form_migration_plugins_alter(array &$migrations) { +- \Drupal::classResolver(MigrationHelper::class) +- ->alterPlugins($migrations); +- } +--- 484,486 ---- + \Drupal::classResolver(MigrationHelper::class) + ->alterRow($row, $source, $migration); + } diff --git a/web/modules/inline_entity_form/src/Element/InlineEntityForm.php b/web/modules/inline_entity_form/src/Element/InlineEntityForm.php index 7de401234457a0be918a434dffa614fbdb3d1bc1..74a71424736eab114f8fae45c5baf1c19475166e 100644 --- a/web/modules/inline_entity_form/src/Element/InlineEntityForm.php +++ b/web/modules/inline_entity_form/src/Element/InlineEntityForm.php @@ -91,7 +91,7 @@ public function getInfo() { * @return array * The built entity form. */ - public static function processEntityForm($entity_form, FormStateInterface $form_state, &$complete_form) { + public static function processEntityForm(array $entity_form, FormStateInterface $form_state, array &$complete_form) { if (empty($entity_form['#entity_type'])) { throw new \InvalidArgumentException('The inline_entity_form element requires the #entity_type property.'); } @@ -162,7 +162,7 @@ public static function processEntityForm($entity_form, FormStateInterface $form_ * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */ - public static function validateEntityForm(&$entity_form, FormStateInterface $form_state) { + public static function validateEntityForm(array &$entity_form, FormStateInterface $form_state) { $inline_form_handler = static::getInlineFormHandler($entity_form['#entity_type']); $inline_form_handler->entityFormValidate($entity_form, $form_state); } @@ -175,7 +175,7 @@ public static function validateEntityForm(&$entity_form, FormStateInterface $for * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */ - public static function submitEntityForm(&$entity_form, FormStateInterface $form_state) { + public static function submitEntityForm(array &$entity_form, FormStateInterface $form_state) { $inline_form_handler = static::getInlineFormHandler($entity_form['#entity_type']); $inline_form_handler->entityFormSubmit($entity_form, $form_state); if ($entity_form['#save_entity']) { diff --git a/web/modules/inline_entity_form/src/ElementSubmit.php b/web/modules/inline_entity_form/src/ElementSubmit.php index 72e08a12288170f0e4c9f146a08dc0708c9df4b3..d2e519257c1a821ec7dd7fb9203dea9f6042d72a 100644 --- a/web/modules/inline_entity_form/src/ElementSubmit.php +++ b/web/modules/inline_entity_form/src/ElementSubmit.php @@ -22,7 +22,7 @@ class ElementSubmit { * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. */ - public static function attach(&$form, FormStateInterface $form_state) { + public static function attach(array &$form, FormStateInterface $form_state) { // attach() is called for each IEF form element, but the callbacks only // need to be added once per form build. if (isset($form['#ief_element_submit_attached'])) { @@ -50,7 +50,7 @@ public static function attach(&$form, FormStateInterface $form_state) { * @param array $complete_form * The complete form. */ - public static function addCallback(&$element, $complete_form) { + public static function addCallback(array &$element, array $complete_form) { if (empty($element['#submit'])) { // Drupal runs either the button-level callbacks or the form-level ones. // Having no button-level callbacks indicates that the form has relied @@ -60,7 +60,7 @@ public static function addCallback(&$element, $complete_form) { $element['#submit'] = array_merge([[get_called_class(), 'trigger']], $element['#submit']); // Used to distinguish between an inline form submit and main form submit. - $element['#ief_submit_trigger'] = TRUE; + $element['#ief_submit_trigger'] = TRUE; $element['#ief_submit_trigger_all'] = TRUE; } @@ -72,7 +72,7 @@ public static function addCallback(&$element, $complete_form) { * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. */ - public static function trigger(&$form, FormStateInterface $form_state) { + public static function trigger(array &$form, FormStateInterface $form_state) { $triggered_element = $form_state->getTriggeringElement(); if (!empty($triggered_element['#ief_submit_trigger_all'])) { // The parent form was submitted, process all IEFs and their children. @@ -95,7 +95,7 @@ public static function trigger(&$form, FormStateInterface $form_state) { * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. */ - public static function doSubmit(&$element, FormStateInterface $form_state) { + public static function doSubmit(array &$element, FormStateInterface $form_state) { // Recurse through all children. foreach (Element::children($element) as $key) { if (!empty($element[$key])) { diff --git a/web/modules/inline_entity_form/src/Form/EntityInlineForm.php b/web/modules/inline_entity_form/src/Form/EntityInlineForm.php index 22533e62f2345baf03a9bf1e45a6090b62fc2539..9f59c013e291d1f73faa298e1f6d8ed030e91e0d 100644 --- a/web/modules/inline_entity_form/src/Form/EntityInlineForm.php +++ b/web/modules/inline_entity_form/src/Form/EntityInlineForm.php @@ -12,7 +12,6 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Render\Element; use Drupal\inline_entity_form\InlineFormInterface; @@ -173,7 +172,10 @@ public function entityForm(array $entity_form, FormStateInterface $form_state) { $entity = $entity_form['#entity']; $form_display = $this->getFormDisplay($entity, $entity_form['#form_mode']); $form_display->buildForm($entity, $entity_form, $form_state); - $entity_form['#ief_element_submit'][] = [get_class($this), 'submitCleanFormState']; + $entity_form['#ief_element_submit'][] = [ + get_class($this), + 'submitCleanFormState', + ]; // Inline entities inherit the parent language. $langcode_key = $this->entityType->getKey('langcode'); if ($langcode_key && isset($entity_form[$langcode_key])) { @@ -234,6 +236,7 @@ public function entityForm(array $entity_form, FormStateInterface $form_state) { $entity_form[$child]['#group'] = implode('][', $entity_form[$entity_form[$child]['#group']]['#parents']); } } + $entity_form['#attached']['library'][] = 'core/drupal.form'; return $entity_form; } @@ -253,9 +256,10 @@ public function entityFormValidate(array &$entity_form, FormStateInterface $form $form_display->validateFormValues($entity, $entity_form, $form_state); $entity->setValidationRequired(FALSE); - 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. + // $form_state->setErrorByName($name, $message) may suppress the error + // message. $form_state->setError($triggering_element, $message); } } @@ -303,7 +307,10 @@ protected function buildEntity(array $entity_form, ContentEntityInterface $entit // Invoke all specified builders for copying form values to entity fields. if (isset($entity_form['#entity_builders'])) { foreach ($entity_form['#entity_builders'] as $function) { - call_user_func_array($function, [$entity->getEntityTypeId(), $entity, &$entity_form, &$form_state]); + call_user_func_array( + $function, + [$entity->getEntityTypeId(), $entity, &$entity_form, &$form_state] + ); } } } @@ -313,15 +320,16 @@ protected function buildEntity(array $entity_form, ContentEntityInterface $entit * * After field_attach_submit() has run and the form has been closed, the form * state still contains field data in $form_state->get('field'). Unless that - * data is removed, the next form with the same #parents (reopened add form, - * for example) will contain data (i.e. uploaded files) from the previous form. + * data is removed, the next form with the same #parents (reopened add + * form, for example) will contain data (i.e. uploaded files) from the + * previous form. * - * @param $entity_form + * @param array $entity_form * The entity form. - * @param $form_state + * @param Drupal\Core\Form\FormStateInterface $form_state * The form state of the parent form. */ - public static function submitCleanFormState(&$entity_form, FormStateInterface $form_state) { + public static function submitCleanFormState(array &$entity_form, FormStateInterface $form_state) { /** @var \Drupal\Core\Entity\EntityInterface $entity */ $entity = $entity_form['#entity']; $bundle = $entity->bundle(); diff --git a/web/modules/inline_entity_form/src/Form/NodeInlineForm.php b/web/modules/inline_entity_form/src/Form/NodeInlineForm.php index 1c00b6acdf4fdb027b0a3f1ca728bb480e02b82f..85a263114393ca6c76667f75ece5760d6948973b 100644 --- a/web/modules/inline_entity_form/src/Form/NodeInlineForm.php +++ b/web/modules/inline_entity_form/src/Form/NodeInlineForm.php @@ -2,7 +2,6 @@ namespace Drupal\inline_entity_form\Form; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; /** diff --git a/web/modules/inline_entity_form/src/InlineFormInterface.php b/web/modules/inline_entity_form/src/InlineFormInterface.php index 5bbd02dba8453b6a178206ea1a96d3298004a526..d68ef29536d15d65fa4c4715c1adbe7ccaad32e3 100644 --- a/web/modules/inline_entity_form/src/InlineFormInterface.php +++ b/web/modules/inline_entity_form/src/InlineFormInterface.php @@ -60,8 +60,7 @@ public function getEntityLabel(EntityInterface $entity); * - 'field': A field value from the entity. The name of the field is * given by the key in this array. * - 'callback': A callback, given by the 'callback' property. - * @see template_preprocess_inline_entity_form_entity_table() for the - * handling of these. + * @see template_preprocess_inline_entity_form_entity_table() * - label: the title of the table field's column in the IEF table. * - weight: the sort order of the column in the IEF table. * - display_options: (optional) used for 'field' type table columns, an @@ -72,7 +71,7 @@ public function getEntityLabel(EntityInterface $entity); * to the callback. The entity and the theme variables are always passed * as as the first two arguments. */ - public function getTableFields($bundles); + public function getTableFields(array $bundles); /** * Checks whether tabledrag should be enabled for the given table. @@ -83,7 +82,7 @@ public function getTableFields($bundles); * @return bool * TRUE if tabledrag should be enabled, FALSE otherwise. */ - public function isTableDragEnabled($element); + public function isTableDragEnabled(array $element); /** * Builds the entity form. @@ -142,6 +141,6 @@ public function save(EntityInterface $entity); * - parent_entity_type: The type of the parent entity. * - parent_entity: The parent entity. */ - public function delete($ids, $context); + public function delete(array $ids, array $context); } diff --git a/web/modules/inline_entity_form/src/MigrationHelper.php b/web/modules/inline_entity_form/src/MigrationHelper.php index dc949cf4222e29566b64e829ea9bf2d2198fff49..51dc1aae35be72a10e08760f8547b8dfe6e34708 100644 --- a/web/modules/inline_entity_form/src/MigrationHelper.php +++ b/web/modules/inline_entity_form/src/MigrationHelper.php @@ -25,18 +25,26 @@ class MigrationHelper { */ public function alterPlugins(array &$migrations) { foreach ($migrations as &$migration) { - /** @var \Drupal\migrate\Plugin\MigratePluginManager $migration_plugin_manager */ - $migration_plugin_manager = \Drupal::service('plugin.manager.migration'); - $migration_stub = $migration_plugin_manager->createStubMigration($migration); /** @var \Drupal\migrate\Plugin\MigrateSourcePluginManager $source_plugin_manager */ $source_plugin_manager = \Drupal::service('plugin.manager.migrate.source'); $source = NULL; - $configuration = $migration['source']; - $source = $source_plugin_manager->createInstance($migration['source']['plugin'], $configuration, $migration_stub); - if ($source) { + if (!empty($migration['migration_group'])) { + // Integrate shared group configuration into the migration, in order to + // have full migration definitions in place. + $this->getMigrationWithSharedConfiguration($migration); + } + if (isset($migration['source']['plugin'])) { + $source = $source_plugin_manager->getDefinition($migration['source']['plugin']); + } + if (isset($source['class'])) { // Field instance. - if (get_class($source) === FieldInstance::class) { + if ($source['class'] === FieldInstance::class) { $settings = $migration['process']['settings']; + if (isset($settings['plugin'])) { + // Prepare for multiple plugins, + // as there was only one before: + $settings = [$settings]; + } $addition = [ 'inline_entity_form' => [ 'plugin' => 'inline_entity_form_field_instance_settings', @@ -45,12 +53,15 @@ public function alterPlugins(array &$migrations) { $settings = NestedArray::mergeDeepArray([$settings, $addition], TRUE); $migration['process']['settings'] = $settings; } - if (is_a($source, FieldInstancePerFormDisplay::class)) { - $addition = [ - 'inline_entity_form_single' => 'inline_entity_form_simple', - 'inline_entity_form' => 'inline_entity_form_complex', - ]; - $migration['process']['options/type']['type']['map'] = array_merge($migration['process']['options/type']['type']['map'], $addition); + if (is_a($source['class'], FieldInstancePerFormDisplay::class, TRUE)) { + // Ensure the map exists and is an array: + if (!empty($migration['process']['options/type']['type']['map']) && is_array($migration['process']['options/type']['type']['map'])) { + $map_addition = [ + 'inline_entity_form_single' => 'inline_entity_form_simple', + 'inline_entity_form' => 'inline_entity_form_complex', + ]; + $migration['process']['options/type']['type']['map'] = array_merge($migration['process']['options/type']['type']['map'], $map_addition); + } } } } @@ -132,4 +143,36 @@ protected function getBundles(MigrateSourceInterface $source_plugin, $entity_typ return $bundles; } + /** + * Helper to get the full migration with shared configuration. + * + * @param array $migration + * The migration to process. + */ + protected function getMigrationWithSharedConfiguration(array &$migration) { + // Integrate shared group configuration into the migration. + if (!empty($migration['migration_group'])) { + $group = \Drupal\migrate_plus\Entity\MigrationGroup::load($migration['migration_group']); + $shared_configuration = !empty($group) ? $group->get('shared_configuration') : []; + if (!empty($shared_configuration)) { + foreach ($shared_configuration as $key => $group_value) { + $migration_value = $migration[$key] ?? NULL; + // Where both the migration and the group provide arrays, replace + // recursively (so each key collision is resolved in favor of the + // migration). + if (is_array($migration_value) && is_array($group_value)) { + $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. + elseif (is_null($migration_value)) { + $migration[$key] = $group_value; + } + // Otherwise, the existing migration value overrides the group value. + } + } + } + } + } diff --git a/web/modules/inline_entity_form/src/MigrationHelper.php.rej b/web/modules/inline_entity_form/src/MigrationHelper.php.rej new file mode 100644 index 0000000000000000000000000000000000000000..71b30786d1fceb5206980bfc73418d4c9fdd4f9f --- /dev/null +++ b/web/modules/inline_entity_form/src/MigrationHelper.php.rej @@ -0,0 +1,17 @@ +*************** +*** 36,42 **** + if ($source) { + // Field instance. + if (get_class($source) === FieldInstance::class) { +- $settings[] = $migration['process']['settings']; + $addition = [ + 'inline_entity_form' => [ + 'plugin' => 'inline_entity_form_field_instance_settings', +--- 36,42 ---- + if ($source) { + // Field instance. + if (get_class($source) === FieldInstance::class) { ++ $settings = $migration['process']['settings']; + $addition = [ + 'inline_entity_form' => [ + 'plugin' => 'inline_entity_form_field_instance_settings', diff --git a/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php b/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php index 0d0761dfb4ce14968694419f334f24557cf946dc..592ece30d67aaff36e2d7d511e45d4c4991a7c36 100644 --- a/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php +++ b/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php @@ -128,10 +128,10 @@ public function __wakeup() { /** * Sets inline entity form ID. * - * @see ::makeIefId - * * @param string $ief_id * The inline entity form ID. + * + * @see ::makeIefId */ protected function setIefId($ief_id) { $this->iefId = $ief_id; @@ -157,10 +157,11 @@ protected function getIefId() { * Also, "add" and "edit" IEFs have different array parents, which messes up * form state, so we fixup this here with a, errrm, pragmatic hack. * - * @see \Drupal\inline_entity_form\WidgetSubmit::doSubmit - * * @param string[] $parents * The array parents. + * + * @see \Drupal\inline_entity_form\WidgetSubmit::doSubmit + * * @return string * The resulting inline entity form ID. */ @@ -302,7 +303,10 @@ public function settingsSummary() { if ($this->getSetting('override_labels')) { $summary[] = $this->t( 'Overriden labels are used: %singular and %plural', - ['%singular' => $this->getSetting('label_singular'), '%plural' => $this->getSetting('label_plural')] + [ + '%singular' => $this->getSetting('label_singular'), + '%plural' => $this->getSetting('label_plural'), + ] ); } else { @@ -314,7 +318,7 @@ public function settingsSummary() { } if ($this->getSetting('collapsible')) { - $summary[] = $this->t($this->getSetting('collapsed') ? 'Collapsible, collapsed by default' : 'Collapsible'); + $summary[] = $this->getSetting('collapsed') ? $this->t('Collapsible, collapsed by default') : $this->t('Collapsible'); } return $summary; @@ -383,7 +387,8 @@ protected function prepareFormState(FormStateInterface $form_state, FieldItemLis 'delete' => [], 'entities' => [], ]; - // Store the $items entities in the widget state, for further manipulation. + // Store the $items entities in the widget state, for further + // manipulation. foreach ($items->referencedEntities() as $delta => $entity) { // Display the entity in the correct translation. if ($translating) { @@ -409,6 +414,8 @@ protected function prepareFormState(FormStateInterface $form_state, FieldItemLis * Entity bundle. * @param string $langcode * Entity langcode. + * @param string $delta + * Delta. * @param array $parents * Array of parent element names. * @param \Drupal\Core\Entity\EntityInterface $entity @@ -457,6 +464,8 @@ protected function getInlineEntityForm($operation, $bundle, $langcode, $delta, a * TRUE if translating is in progress, FALSE otherwise. * * @see \Drupal\inline_entity_form\TranslationHelper::initFormLangcodes() + * + * @todo Replace line 472 \Drupal call with Dependency Injection. */ protected function isTranslating(FormStateInterface $form_state) { if (TranslationHelper::isTranslating($form_state)) { @@ -493,7 +502,7 @@ public static function removeTranslatabilityClue(array $element, FormStateInterf * @param array $element * Form array structure. */ - public static function addIefSubmitCallbacks($element) { + public static function addIefSubmitCallbacks(array $element) { $element['#ief_element_submit'][] = [get_called_class(), 'submitSaveEntity']; return $element; } @@ -504,12 +513,12 @@ public static function addIefSubmitCallbacks($element) { * Note that at this point the entity is not yet saved, since the user might * still decide to cancel the parent form. * - * @param $entity_form + * @param array $entity_form * The form of the entity being managed inline. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state of the parent form. */ - public static function submitSaveEntity($entity_form, FormStateInterface $form_state) { + public static function submitSaveEntity(array $entity_form, FormStateInterface $form_state) { $ief_id = $entity_form['#ief_id']; /** @var \Drupal\Core\Entity\EntityInterface $entity */ $entity = $entity_form['#entity']; @@ -590,6 +599,7 @@ public function form(FieldItemListInterface $items, array &$form, FormStateInter * Determines if the current user can add any new entities. * * @return bool + * Returns bool to allow or not new entity additions. */ protected function canAddNew() { $create_bundles = $this->getCreateBundles(); diff --git a/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php b/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php index 12cff2c117c0ac558617c78c133dea624b16b135..be55aa7fe883d9b685a5ab9c6c4e91b2f2e5cb49 100644 --- a/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php +++ b/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php @@ -226,7 +226,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element = [ '#type' => $this->getSetting('collapsible') ? 'details' : 'fieldset', '#tree' => TRUE, - '#description' => $this->fieldDefinition->getDescription(), + '#description' => $this->getFilteredDescription(), '#prefix' => '<div id="' . $wrapper . '">', '#suffix' => '</div>', '#ief_id' => $this->getIefId(), @@ -243,7 +243,10 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen } $this->prepareFormState($form_state, $items, $element['#translating']); - $entities = $form_state->get(['inline_entity_form', $this->getIefId(), 'entities']); + $entities = $form_state->get([ + 'inline_entity_form', $this->getIefId(), + 'entities', + ]); // Prepare cardinality information. $entities_count = count($entities); @@ -251,7 +254,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $cardinality_reached = ($cardinality > 0 && $entities_count == $cardinality); // Build the "Multiple value" widget. - // TODO - does this belong in #element_validate? + // @todo does this belong in #element_validate? $element['#element_validate'][] = [get_class($this), 'updateRowWeights']; // Add the required element marker & validation. if ($element['#required']) { @@ -308,13 +311,19 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $entity->bundle(), $parent_langcode, $key, - array_merge($parents, ['inline_entity_form', 'entities', $key, 'form']), + array_merge( + $parents, + ['inline_entity_form', 'entities', $key, 'form'] + ), $value['form'] == 'edit' ? $entity : $entity->createDuplicate() ), ]; $element['entities'][$key]['form']['inline_entity_form']['#process'] = [ - ['\Drupal\inline_entity_form\Element\InlineEntityForm', 'processEntityForm'], + [ + '\Drupal\inline_entity_form\Element\InlineEntityForm', + 'processEntityForm', + ], [get_class($this), 'addIefSubmitCallbacks'], [get_class($this), 'buildEntityFormActions'], ]; @@ -445,7 +454,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $hide_cancel = TRUE; } elseif ($create_bundles_count == 1 && $allow_new && !$settings['allow_existing']) { - $bundle = reset($target_bundles); + $bundle = reset($create_bundles); // The parent entity type and bundle must not be the same as the inline // entity type and bundle, to prevent recursion. @@ -453,16 +462,19 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $parent_bundle = $this->fieldDefinition->getTargetBundle(); if ($parent_entity_type != $target_type || $parent_bundle != $bundle) { $form_state->set(['inline_entity_form', $this->getIefId(), 'form'], 'add'); - $form_state->set(['inline_entity_form', $this->getIefId(), 'form settings'], [ - 'bundle' => $bundle, - ]); + $form_state->set( + ['inline_entity_form', $this->getIefId(), 'form settings'], + ['bundle' => $bundle] + ); $hide_cancel = TRUE; } } } // If no form is open, show buttons that open one. - $open_form = $form_state->get(['inline_entity_form', $this->getIefId(), 'form']); + $open_form = $form_state->get( + ['inline_entity_form', $this->getIefId(), 'form'] + ); if (empty($open_form)) { $element['actions'] = [ @@ -542,7 +554,10 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ), ]; $element['form']['inline_entity_form']['#process'] = [ - ['\Drupal\inline_entity_form\Element\InlineEntityForm', 'processEntityForm'], + [ + '\Drupal\inline_entity_form\Element\InlineEntityForm', + 'processEntityForm', + ], [get_class($this), 'addIefSubmitCallbacks'], [get_class($this), 'buildEntityFormActions'], ]; @@ -567,6 +582,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // Pre-opened forms can't be closed in order to force the user to // add / reference an entity. if ($hide_cancel) { + $process_element = []; if ($open_form == 'add') { $process_element = &$element['form']['inline_entity_form']; } @@ -617,7 +633,7 @@ public function extractFormValues(FieldItemListInterface $items, array $form, Fo } elseif ($widget_state['form'] == 'ief_add_existing') { $parent = NestedArray::getValue($form, [$field_name, 'widget', 'form']); - $element = isset($parent['entity_id']) ? $parent['entity_id'] : []; + $element = $parent['entity_id'] ?? []; if (!empty($element['#value'])) { $options = [ 'target_type' => $element['#target_type'], @@ -630,7 +646,8 @@ public function extractFormValues(FieldItemListInterface $items, array $form, Fo foreach ($input_values as $input) { $match = EntityAutocomplete::extractEntityIdFromAutocompleteInput($input); if ($match === NULL) { - // Try to get a match from the input string when the user didn't use + // Try to get a match from the input string when the user didn't + // use. // the autocomplete but filled in a value manually. $entities_by_bundle = $handler->getReferenceableEntities($input, '='); $entities = array_reduce($entities_by_bundle, function ($flattened, $bundle_entities) { @@ -688,7 +705,7 @@ public function extractFormValues(FieldItemListInterface $items, array $form, Fo * @param array $element * Form array structure. */ - public static function buildEntityFormActions($element) { + public static function buildEntityFormActions(array $element) { // Build a delta suffix that's appended to button #name keys for uniqueness. $delta = $element['#ief_id']; if ($element['#op'] == 'add') { @@ -743,7 +760,10 @@ public static function buildEntityFormActions($element) { $element['actions']['ief_' . $element['#op'] . '_cancel']['#ief_row_delta'] = $element['#ief_row_delta']; static::addSubmitCallbacks($element['actions']['ief_' . $element['#op'] . '_save']); - $element['actions']['ief_' . $element['#op'] . '_save']['#submit'][] = [get_called_class(), 'submitCloseRow']; + $element['actions']['ief_' . $element['#op'] . '_save']['#submit'][] = [ + get_called_class(), + 'submitCloseRow', + ]; $element['actions']['ief_' . $element['#op'] . '_cancel']['#submit'] = [ [get_called_class(), 'closeChildForms'], [get_called_class(), 'submitCloseRow'], @@ -760,7 +780,7 @@ public static function buildEntityFormActions($element) { * @param array $element * Form array structure. */ - public static function hideCancel($element) { + public static function hideCancel(array $element) { // @todo Name both buttons the same and simplify this logic. if (isset($element['actions']['ief_add_cancel'])) { $element['actions']['ief_add_cancel']['#access'] = FALSE; @@ -778,7 +798,7 @@ public static function hideCancel($element) { * @param array $form * Form array structure. */ - protected function buildRemoveForm(&$form) { + protected function buildRemoveForm(array &$form) { /** @var \Drupal\Core\Entity\EntityInterface $entity */ $entity = $form['#entity']; $entity_id = $entity->id(); @@ -842,14 +862,14 @@ protected function buildRemoveForm(&$form) { /** * Button #submit callback: Closes a row form in the IEF widget. * - * @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. * * @see inline_entity_form_open_row_form() */ - public static function submitCloseRow($form, FormStateInterface $form_state) { + public static function submitCloseRow(array $form, FormStateInterface $form_state) { $element = inline_entity_form_get_element($form, $form_state); $ief_id = $element['#ief_id']; $delta = $form_state->getTriggeringElement()['#ief_row_delta']; @@ -858,7 +878,6 @@ public static function submitCloseRow($form, FormStateInterface $form_state) { $form_state->set(['inline_entity_form', $ief_id, 'entities', $delta, 'form'], NULL); } - /** * Remove form submit callback. * @@ -867,12 +886,12 @@ public static function submitCloseRow($form, FormStateInterface $form_state) { * This isn't an #element_validate callback to avoid processing the * remove form when the main form is submitted. * - * @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. */ - public static function submitConfirmRemove($form, FormStateInterface $form_state) { + public static function submitConfirmRemove(array $form, FormStateInterface $form_state) { $element = inline_entity_form_get_element($form, $form_state); $remove_button = $form_state->getTriggeringElement(); $delta = $remove_button['#ief_row_delta']; @@ -905,7 +924,7 @@ public static function submitConfirmRemove($form, FormStateInterface $form_state * @return string * Bundle machine name. * - * @TODO - Figure out if can be simplified. + * @todo Figure out if can be simplified. */ protected function determineBundle(FormStateInterface $form_state) { $ief_settings = $form_state->get(['inline_entity_form', $this->getIefId()]); @@ -927,10 +946,12 @@ protected function determineBundle(FormStateInterface $form_state) { public static function updateRowWeights($element, FormStateInterface $form_state, $form) { $ief_id = $element['#ief_id']; - // Loop over the submitted delta values and update the weight of the entities - // in the form state. + // Loop over the submitted delta values and update the weight of the + // entities in the form state. foreach (Element::children($element['entities']) as $key) { - $form_state->set(['inline_entity_form', $ief_id, 'entities', $key, 'weight'], $element['entities'][$key]['delta']['#value']); + $form_state->set( + ['inline_entity_form', $ief_id, 'entities', $key, 'weight'], + $element['entities'][$key]['delta']['#value']); } } @@ -956,14 +977,14 @@ public static function requiredField($element, FormStateInterface $form_state, $ /** * Button #submit callback: Closes a form in the IEF widget. * - * @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. * * @see inline_entity_form_open_form() */ - public static function closeForm($form, FormStateInterface $form_state) { + public static function closeForm(array $form, FormStateInterface $form_state) { $element = inline_entity_form_get_element($form, $form_state); $ief_id = $element['#ief_id']; @@ -974,14 +995,18 @@ public static function closeForm($form, FormStateInterface $form_state) { /** * Add common submit callback functions and mark element as a IEF trigger. * - * @param $element + * @param array $element + * Form array structure. */ - public static function addSubmitCallbacks(&$element) { + public static function addSubmitCallbacks(array &$element) { $element['#submit'] = [ ['\Drupal\inline_entity_form\ElementSubmit', 'trigger'], - ['\Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex', 'closeForm'], + [ + '\Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex', + 'closeForm', + ], ]; - $element['#ief_submit_trigger'] = TRUE; + $element['#ief_submit_trigger'] = TRUE; } /** @@ -990,12 +1015,12 @@ public static function addSubmitCallbacks(&$element) { * Used to ensure that forms in nested IEF widgets are properly closed * when a parent IEF's form gets submitted or cancelled. * - * @param $form + * @param array $form * The IEF Form element. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state of the parent form. */ - public static function closeChildForms($form, FormStateInterface &$form_state) { + public static function closeChildForms(array $form, FormStateInterface &$form_state) { $element = inline_entity_form_get_element($form, $form_state); inline_entity_form_close_all_forms($element, $form_state); } diff --git a/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php b/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php index 9f799773fabf22eba7c949ea14259e4efcb46647..51e0acca397a35054ce08568a32d1ca76cdc8912 100644 --- a/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php +++ b/web/modules/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php @@ -59,7 +59,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $parents = array_merge($element['#field_parents'], [ $items->getName(), $delta, - 'inline_entity_form' + 'inline_entity_form', ]); $bundle = $this->getBundle(); $element['inline_entity_form'] = $this->getInlineEntityForm($op, $bundle, $langcode, $delta, $parents, $entity); @@ -134,11 +134,15 @@ public function extractFormValues(FieldItemListInterface $items, array $form, Fo $submitted_values = $form_state->getValue($parents); $values = []; foreach ($items as $delta => $value) { - $element = NestedArray::getValue($form, [$field_name, 'widget', $delta]); - /** @var \Drupal\Core\Entity\EntityInterface $entity */ - $entity = $element['inline_entity_form']['#entity']; - $weight = isset($submitted_values[$delta]['_weight']) ? $submitted_values[$delta]['_weight'] : 0; - $values[$weight] = ['entity' => $entity]; + if ($element = NestedArray::getValue( + $form, + [$field_name, 'widget', $delta] + )) { + /** @var \Drupal\Core\Entity\EntityInterface $entity */ + $entity = $element['inline_entity_form']['#entity']; + $weight = $submitted_values[$delta]['_weight'] ?? 0; + $values[$weight] = ['entity' => $entity]; + } } // Sort items base on weights. @@ -173,7 +177,7 @@ public function extractFormValues(FieldItemListInterface $items, array $form, Fo $field_name = $this->fieldDefinition->getName(); $field_state = WidgetBase::getWidgetState($form['#parents'], $field_name, $form_state); foreach ($items as $delta => $item) { - $field_state['original_deltas'][$delta] = isset($item->_original_delta) ? $item->_original_delta : $delta; + $field_state['original_deltas'][$delta] = $item->_original_delta ?? $delta; unset($item->_original_delta, $item->weight); } WidgetBase::setWidgetState($form['#parents'], $field_name, $form_state, $field_state); diff --git a/web/modules/inline_entity_form/src/ReferenceUpgrader.php b/web/modules/inline_entity_form/src/ReferenceUpgrader.php index dfb1b0ae5803e0b9d826a6433f24d6d024ceb700..e533d7e20bd088eebbe4033189b05903e1548c9e 100644 --- a/web/modules/inline_entity_form/src/ReferenceUpgrader.php +++ b/web/modules/inline_entity_form/src/ReferenceUpgrader.php @@ -9,7 +9,7 @@ use Drupal\Core\Field\TypedData\FieldItemDataDefinitionInterface; /** - * Class ReferenceUpgrader + * Class ReferenceUpgrader. * * When saving nested IEFs inside-out, after saving an inner entity, we must * "upgrade" its reference item with e.g. revision ID information. @@ -25,17 +25,26 @@ final class ReferenceUpgrader { */ private $entities = []; + /** + * Registers entities. + */ public function registerEntity(EntityInterface $entity) { $entityId = $entity->id() ?? $this->throwNeedsId(); $this->entities[$entity->getEntityTypeId()][$entityId] = $entity; } + /** + * Throws exceptions on trying to register entities without id. + */ private function throwNeedsId() { throw new \RuntimeException("Can only register entity with ID."); } + /** + * Upgrades entities references. + */ public function upgradeEntityReferences(FieldableEntityInterface $entity) { - foreach ($entity as $fieldName => $fieldItemList) { + foreach ($entity as $fieldItemList) { if ( $fieldItemList instanceof EntityReferenceFieldItemListInterface && ($targetEntityType = $fieldItemList->getFieldDefinition()->getSetting('target_type')) diff --git a/web/modules/inline_entity_form/src/WidgetSubmit.php b/web/modules/inline_entity_form/src/WidgetSubmit.php index a8a4eccb8beb9cd712d4c6cdf4b7814d592b9b05..6fec63957d29255888041553d8a0c6b26e3d8b0a 100644 --- a/web/modules/inline_entity_form/src/WidgetSubmit.php +++ b/web/modules/inline_entity_form/src/WidgetSubmit.php @@ -22,7 +22,7 @@ class WidgetSubmit { * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. */ - public static function attach(&$form, FormStateInterface $form_state) { + public static function attach(array &$form, FormStateInterface $form_state) { // $form['#ief_element_submit'] runs after the #ief_element_submit // callbacks of all subelements, which means that doSubmit() has // access to the final IEF $form_state. @@ -45,9 +45,9 @@ public static function doSubmit(array $form, FormStateInterface $form_state) { // forms before outer forms, to ensure inside-out saving of entities. // @see \Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormBase::makeIefId krsort($widget_states, SORT_STRING); - foreach ($widget_states as $ief_id => &$widget_state) { + foreach ($widget_states as &$widget_state) { $widget_state += ['entities' => [], 'delete' => []]; - foreach ($widget_state['entities'] as $delta => &$entity_item) { + foreach ($widget_state['entities'] as &$entity_item) { if (!empty($entity_item['entity']) && !empty($entity_item['needs_save'])) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $entity_item['entity']; diff --git a/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/config/install/field.field.node.ief_test_complex.multi.yml b/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/config/install/field.field.node.ief_test_complex.multi.yml index ec939eb5136106d6d3afb43402c6dfdc247e35ca..389fce7255ec27a7f7f732a07819a3fb80cb23db 100644 --- a/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/config/install/field.field.node.ief_test_complex.multi.yml +++ b/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/config/install/field.field.node.ief_test_complex.multi.yml @@ -15,7 +15,7 @@ field_name: multi entity_type: node bundle: ief_test_complex label: Multiple nodes -description: 'Reference multiple nodes.' +description: 'Reference multiple nodes. A complex widget on [site:name].' required: true translatable: false default_value: { } diff --git a/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/inline_entity_form_test.info.yml b/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/inline_entity_form_test.info.yml index eb231fadad127b44e2db95c9023cfdc840b24126..71529af7ed226bddcd77328bd01e6204461a5822 100644 --- a/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/inline_entity_form_test.info.yml +++ b/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/inline_entity_form_test.info.yml @@ -9,7 +9,7 @@ dependencies: - drupal:file - drupal:image -# Information added by Drupal.org packaging script on 2021-04-11 -version: '8.x-1.0-rc9' +# Information added by Drupal.org packaging script on 2022-09-20 +version: '8.x-1.0-rc14' project: 'inline_entity_form' -datestamp: 1618174489 +datestamp: 1663701307 diff --git a/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/inline_entity_form_test.routing.yml b/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/inline_entity_form_test.routing.yml index 9cf5a051811e8236b7d1e34d954a786580b497a0..6c6fda5db264daed2a177edd670f8ff67c30d645 100644 --- a/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/inline_entity_form_test.routing.yml +++ b/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/inline_entity_form_test.routing.yml @@ -6,4 +6,5 @@ inline_entity_form_test.form: form_mode: 'default' node: NULL requirements: + # Needs to be accessed by an anonymous user. _access: 'TRUE' diff --git a/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/src/IefTest.php b/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/src/IefTest.php index dc27f8110071eded8de908c17db831d78aebc956..c6a89b59f127d1219dfcca1b2184edbd8389890a 100644 --- a/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/src/IefTest.php +++ b/web/modules/inline_entity_form/tests/modules/inline_entity_form_test/src/IefTest.php @@ -14,7 +14,7 @@ class IefTest extends FormBase { /** * {@inheritdoc} */ - public function getFormID() { + public function getFormId() { return 'ief_test'; } @@ -30,11 +30,11 @@ public function buildForm(array $form, FormStateInterface $form_state, $form_mod ]; $form['submit'] = [ '#type' => 'submit', - '#value' => t('Save'), + '#value' => $this->t('Save'), ]; if (!empty($node)) { $form['inline_entity_form']['#default_value'] = $node; - $form['submit']['#value'] = t('Update'); + $form['submit']['#value'] = $this->t('Update'); } return $form; @@ -45,7 +45,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $form_mod */ public function submitForm(array &$form, FormStateInterface $form_state) { $entity = $form['inline_entity_form']['#entity']; - $message = $this->t('Created @entity_type @label.', ['@entity_type' => $entity->getEntityType()->getLabel(), '@label' => $entity->label()]); + $message = $this->t( + 'Created @entity_type @label.', + [ + '@entity_type' => $entity->getEntityType()->getLabel(), + '@label' => $entity->label(), + ] + ); $this->messenger()->addMessage($message); } diff --git a/web/modules/inline_entity_form/tests/modules/inline_entity_form_translation_test/inline_entity_form_translation_test.info.yml b/web/modules/inline_entity_form/tests/modules/inline_entity_form_translation_test/inline_entity_form_translation_test.info.yml index 9c0b4aa78b0984fb239d51827240ec76b5e5b77e..c9c2418a1ab23b972a9fd4470e3649bf585dc340 100644 --- a/web/modules/inline_entity_form/tests/modules/inline_entity_form_translation_test/inline_entity_form_translation_test.info.yml +++ b/web/modules/inline_entity_form/tests/modules/inline_entity_form_translation_test/inline_entity_form_translation_test.info.yml @@ -8,7 +8,7 @@ dependencies: - drupal:language - drupal:content_translation -# Information added by Drupal.org packaging script on 2021-04-11 -version: '8.x-1.0-rc9' +# Information added by Drupal.org packaging script on 2022-09-20 +version: '8.x-1.0-rc14' project: 'inline_entity_form' -datestamp: 1618174489 +datestamp: 1663701307 diff --git a/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexSimpleWidgetTest.php b/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexSimpleWidgetTest.php index 962ed2989fb0551a226e7335b1c3acbfea107da2..3d77da7e88dd0f42be391cee244f9ccca7e875fc 100644 --- a/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexSimpleWidgetTest.php +++ b/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexSimpleWidgetTest.php @@ -79,8 +79,8 @@ public function testSimpleInComplex() { ->press(); $this->assertNotEmpty($assert_session->waitForElement('xpath', $outer_title_field_xpath)); } - $outer_title = $this->randomMachineName(8); - $inner_title = $this->randomMachineName(8); + $outer_title = $this->randomMachineName(); + $inner_title = $this->randomMachineName(); $assert_session->elementExists('xpath', $outer_title_field_xpath)->setValue($outer_title); // Simple widget is required so should always show up. No need for // add submit. @@ -97,7 +97,7 @@ public function testSimpleInComplex() { $this->assertNoNodeByTitle($outer_title, 'Outer node was not created when widget submitted.'); $this->assertNoNodeByTitle($inner_title, 'Inner node was not created when widget submitted.'); - $host_title = $this->randomMachineName(8); + $host_title = $this->randomMachineName(); $assert_session->elementExists('xpath', $first_title_field_xpath)->setValue($host_title); $page->pressButton('Save'); $assert_session->pageTextContains("$host_title has been created."); diff --git a/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexWidgetRevisionsTest.php b/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexWidgetRevisionsTest.php index 452b5fa46b2e8a7ca4d011f92d9d92c446a71403..9ca7aaa977966c91999df5f7926c2ecdbee976e8 100644 --- a/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexWidgetRevisionsTest.php +++ b/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexWidgetRevisionsTest.php @@ -2,8 +2,6 @@ namespace Drupal\Tests\inline_entity_form\FunctionalJavascript; -use Drupal\Core\Entity\Display\EntityDisplayInterface; - /** * IEF complex entity reference revisions tests. * @@ -68,7 +66,7 @@ protected function setUp(): void { /** * Data provider for ::testRevisionsAtDepth. */ - public function testRevisionsAtDepthDataProvider(): array { + public function revisionsAtDepthDataProvider(): array { return [ [FALSE], [TRUE], @@ -78,7 +76,7 @@ public function testRevisionsAtDepthDataProvider(): array { /** * Tests saving entity reference revisions' field types at depth. * - * @dataProvider testRevisionsAtDepthDataProvider + * @dataProvider revisionsAtDepthDataProvider */ public function testRevisionsAtDepth(bool $inner_widget_adds_revisions) { $level_2_display_config = $this->entityFormDisplayStorage->load('node.err_level_2.default'); diff --git a/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexWidgetTest.php b/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexWidgetTest.php index 8a38315bfae7b73ff3c2a960863f0ecd3c371ed9..cab3336aa43923dd511a4f95b176ca3bc27cd69e 100644 --- a/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexWidgetTest.php +++ b/web/modules/inline_entity_form/tests/src/FunctionalJavascript/ComplexWidgetTest.php @@ -330,13 +330,13 @@ public function testEntityEditingAndRemoving() { $this->updateSetting('allow_existing', TRUE); // Create three ief_reference_type entities. - $referenceNodes = $this->createReferenceContent(3); + $referenceNodes = $this->createReferenceContent(); $this->drupalCreateNode([ 'type' => 'ief_test_complex', 'title' => 'Some title', 'multi' => array_values($referenceNodes), ]); - /** @var \Drupal\node\NodeInterface $parent_node */ + $parent_node = $this->drupalGetNodeByTitle('Some title'); // Edit the second entity. @@ -391,7 +391,7 @@ public function testEntityEditingAndRemoving() { $this->drupalGet('node/' . $parent_node->id() . '/edit'); $assert_session->elementsCount('css', 'tr.ief-row-entity', 2); $assert_session->elementExists('xpath', '(//input[@value="Remove"])[2]')->press(); - $this->assertNotEmpty($confirm_checkbox = $assert_session->waitForElement('xpath', $first_delete_checkbox_xpath)); + $this->assertNotEmpty($assert_session->waitForElement('xpath', $first_delete_checkbox_xpath)); $assert_session->pageTextContains('Are you sure you want to remove Some reference 3?'); $assert_session->elementExists('xpath', '(//input[@value="Remove"])[2]')->press(); $this->waitForRowRemovedByTitle('Some reference 3'); @@ -423,7 +423,7 @@ public function testReferencingExistingEntities() { $this->updateSetting('allow_existing', TRUE); // Create three ief_reference_type entities. - $referenceNodes = $this->createReferenceContent(3); + $referenceNodes = $this->createReferenceContent(); // Create a node for every bundle available. $bundle_nodes = $this->createNodeForEveryBundle(); @@ -474,7 +474,7 @@ public function testReferencingExistingEntities() { // Check if all remaining nodes from all bundles are referenced. $assert_session->elementsCount('css', 'fieldset[data-drupal-selector="edit-all-bundles"] tr.ief-row-entity', 12); - foreach ($bundle_nodes as $id => $title) { + foreach ($bundle_nodes as $title) { $this->assertRowByTitle($title); } } @@ -569,7 +569,7 @@ public function testDuplicatingEntities() { 'title' => 'Some title', 'multi' => array_values($referenceNodes), ]); - /** @var \Drupal\node\NodeInterface $parent_node */ + $parent_node = $this->drupalGetNodeByTitle('Some title'); $this->drupalGet('node/' . $parent_node->id() . '/edit'); @@ -739,7 +739,7 @@ protected function createReferenceContent($numNodes = 3) { * @param mixed $value * The value to set. */ - protected function updateSetting($name, $value) { + protected function updateSetting(string $name, $value) { /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $display */ $display = $this->entityFormDisplayStorage->load('node.ief_test_complex.default'); $component = $display->getComponent('multi'); @@ -775,7 +775,7 @@ protected function createNodeForEveryBundle() { * @param bool $required * Whether the fields are required. */ - protected function setupNestedComplexForm($required) { + protected function setupNestedComplexForm(bool $required) { $assert_session = $this->assertSession(); $page = $this->getSession()->getPage(); /** @var \Drupal\Core\Field\FieldConfigInterface $ief_test_nested1 */ @@ -821,7 +821,7 @@ protected function openMultiExistingForm() { * @param string $expected_error * The error message that is expected to be shown. */ - protected function checkExistingValidationExpectation($existing_node_text, $expected_error) { + protected function checkExistingValidationExpectation(string $existing_node_text, string $expected_error) { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); $this->openMultiExistingForm(); @@ -945,10 +945,8 @@ public function testNestedCreateAndEditWontClash(bool $required) { $top_title_field_xpath = $this->getXpathForNthInputByLabelText('Title', 1); $nested_title_field_xpath = $this->getXpathForNthInputByLabelText('Title', 2); $double_nested_title_field_xpath = $this->getXpathForNthInputByLabelText('Title', 3); - $second_edit_button_xpath = $this->getXpathForButtonWithValue('Edit', 2); - $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); $this->setupNestedComplexForm($required); @@ -986,7 +984,7 @@ public function testNestedCreateAndEditWontClash(bool $required) { $this->elementWithXpath($this->buttonXpath('Update node 2'))->press(); $this->waitForXpathRemoved($this->buttonXpath('Update node 2')); - // Repeat. Add node 2a and 2a_3 + // Repeat. Add node 2a and 2a_3. $this->elementWithXpath($this->buttonXpath('Add new node 2'))->press(); $this->waitForXpath($this->buttonXpath('Create node 2')); if (!$required) { @@ -1021,6 +1019,17 @@ public function testNestedCreateAndEditWontClash(bool $required) { $assert_session->pageTextContains("IEF test nested 1 $title_1 has been created."); } + /** + * Tests the token replacement in the description field. + */ + public function testTokenReplacementInDescriptionField() { + $assert_session = $this->assertSession(); + $this->drupalGet($this->formContentAddUrl); + + $site_name = \Drupal::token()->replace('[site:name]'); + $assert_session->pageTextContains('Reference multiple nodes. A complex widget on ' . $site_name . '.'); + } + /** * Data provider: FALSE, TRUE. */ @@ -1036,6 +1045,7 @@ public function simpleFalseTrueDataProvider() { * * @param string $xpath * The XPath. + * * @return \Behat\Mink\Element\NodeElement * The element. */ @@ -1044,12 +1054,15 @@ public function elementWithXpath(string $xpath): NodeElement { } /** - * Wait, assert, and return an element via XPath. On fail, save output and throw. + * Wait, assert, and return an element via XPath. + * + * On fail, save output and throw. * * @param string $xpath * The XPath. * @param int $timeout * The timeout in milliseconds. + * * @return \Behat\Mink\Element\NodeElement * The element. */ @@ -1063,20 +1076,23 @@ public function waitForXpath(string $xpath, int $timeout = 10000): NodeElement { } /** - * Wait and assert removal of an element via XPath. On fail, save output and throw. + * Wait and assert removal of an element via XPath. + * + * On fail, save output and throw. * * @param string $xpath * The XPath. * @param int $timeout * The timeout in milliseconds. + * * @return bool - * Returna always true (else throws). + * Returns always true (else throws). */ public function waitForXpathRemoved(string $xpath, int $timeout = 10000): bool { $removed = $this->assertSession()->waitForElementRemoved('xpath', $xpath, $timeout); if (!$removed) { $this->htmlOutput(); - $this->assert($removed); + $this->assertTrue($removed); } return $removed; } @@ -1085,9 +1101,10 @@ public function waitForXpathRemoved(string $xpath, int $timeout = 10000): bool { * Get xpath for a button. * * @param string $label - * The button's label. + * The button's label. * @param int $index * The button's index, defaults to 1. + * * @return string * The XPath. */ diff --git a/web/modules/inline_entity_form/tests/src/FunctionalJavascript/InlineEntityFormTestBase.php b/web/modules/inline_entity_form/tests/src/FunctionalJavascript/InlineEntityFormTestBase.php index d4681dab7cae1f440fa309646e455d2bfbe6afe7..ddc505e64f093ea6acd202bb16b34b2d3b7f1dc1 100644 --- a/web/modules/inline_entity_form/tests/src/FunctionalJavascript/InlineEntityFormTestBase.php +++ b/web/modules/inline_entity_form/tests/src/FunctionalJavascript/InlineEntityFormTestBase.php @@ -65,7 +65,7 @@ protected function prepareSettings() { * @return string * The name of the button. */ - protected function getButtonName($xpath) { + protected function getButtonName(string $xpath) { $retval = ''; /** @var \SimpleXMLElement[] $elements */ if ($elements = $this->xpath($xpath)) { @@ -87,7 +87,7 @@ protected function getButtonName($xpath) { * @param string $message * Message to display. */ - protected function assertNoNodeByTitle($title, $message = '') { + protected function assertNoNodeByTitle(string $title, $message = '') { if (!$message) { $message = "No node with title: $title"; } @@ -106,7 +106,7 @@ protected function assertNoNodeByTitle($title, $message = '') { * @param string $message * Message to display. */ - protected function assertNodeByTitle($title, $content_type = NULL, $message = '') { + protected function assertNodeByTitle(string $title, $content_type = NULL, $message = '') { if (!$message) { $message = "Node with title found: $title"; } @@ -127,7 +127,7 @@ protected function assertNodeByTitle($title, $content_type = NULL, $message = '' * @param string $bundle * (optional) The bundle this entity should have. */ - protected function assertEntityByLabel($label, $entity_type_id = 'node', $bundle = NULL) { + protected function assertEntityByLabel(string $label, $entity_type_id = 'node', $bundle = NULL) { $entity_type_manager = \Drupal::entityTypeManager(); $entity_type = $entity_type_manager->getDefinition($entity_type_id); $label_key = $entity_type->getKey('label'); @@ -155,7 +155,7 @@ protected function assertEntityByLabel($label, $entity_type_id = 'node', $bundle * @param string $prefix * The config prefix. */ - protected function checkFormDisplayFields($form_display, $prefix) { + protected function checkFormDisplayFields(string $form_display, string $prefix) { $assert_session = $this->assertSession(); $form_display_fields = [ 'node.ief_test_custom.default' => [ @@ -194,7 +194,7 @@ protected function checkFormDisplayFields($form_display, $prefix) { $assert_session->fieldExists($prefix . $expected_field); } foreach ($fields['unexpected'] as $unexpected_field) { - $assert_session->fieldNotExists($prefix . $unexpected_field, NULL); + $assert_session->fieldNotExists($prefix . $unexpected_field); } } @@ -204,7 +204,7 @@ protected function checkFormDisplayFields($form_display, $prefix) { * @param string $title * The title of the row for which to wait. */ - protected function waitForRowByTitle($title) { + protected function waitForRowByTitle(string $title) { $this->assertNotEmpty($this->assertSession()->waitForElement('xpath', '//td[@class="inline-entity-form-node-label" and text()="' . $title . '"]')); } @@ -214,7 +214,7 @@ protected function waitForRowByTitle($title) { * @param string $title * The title of the row for which to wait. */ - protected function waitForRowRemovedByTitle($title) { + protected function waitForRowRemovedByTitle(string $title) { $this->assertNotEmpty($this->assertSession()->waitForElementRemoved('xpath', '//td[@class="inline-entity-form-node-label" and text()="' . $title . '"]')); } @@ -227,7 +227,7 @@ protected function waitForRowRemovedByTitle($title) { * @return \Behat\Mink\Element\NodeElement * The <td> element containing the label for the IEF row. */ - protected function assertRowByTitle($title) { + protected function assertRowByTitle(string $title) { $this->assertNotEmpty($element = $this->assertSession()->elementExists('xpath', '//td[@class="inline-entity-form-node-label" and text()="' . $title . '"]')); return $element; } @@ -238,7 +238,7 @@ protected function assertRowByTitle($title) { * @param string $title * The title of the row to check. */ - protected function assertNoRowByTitle($title) { + protected function assertNoRowByTitle(string $title) { $this->assertSession()->elementNotExists('xpath', '//td[@class="inline-entity-form-node-label" and text()="' . $title . '"]'); } @@ -255,8 +255,8 @@ protected function assertNoRowByTitle($title) { * @return string * The xpath selector for the input to select. */ - protected function getXpathForNthInputByLabelText($label, $index) { - return "(//*[@id=string((//label[.='{$label}']/@for)[{$index}])])"; + protected function getXpathForNthInputByLabelText(string $label, int $index) { + return "(//*[@id=string((//label[.='$label']/@for)[$index])])"; } /** @@ -274,7 +274,7 @@ protected function getXpathForAutoCompleteInput() { * * Note: index starts at 1. * - * @param string @value + * @param string $value * The text on the button to select. * @param int $index * The index of the button to select. @@ -282,8 +282,8 @@ protected function getXpathForAutoCompleteInput() { * @return string * The xpath selector for the button to select. */ - protected function getXpathForButtonWithValue($value, $index) { - return "(//input[@type='submit' and @value='{$value}'])[{$index}]"; + protected function getXpathForButtonWithValue(string $value, int $index) { + return "(//input[@type='submit' and @value='$value'])[$index]"; } /** @@ -297,8 +297,8 @@ protected function getXpathForButtonWithValue($value, $index) { * @return string * The xpath selector for the fieldset label to select. */ - protected function getXpathForFieldsetLabel($label, $index) { - return "(//fieldset/legend/span[.='{$label}'])[{$index}]"; + protected function getXpathForFieldsetLabel(string $label, int $index) { + return "(//fieldset/legend/span[.='{$label}'])[$index]"; } } diff --git a/web/modules/inline_entity_form/tests/src/FunctionalJavascript/SimpleWidgetTest.php b/web/modules/inline_entity_form/tests/src/FunctionalJavascript/SimpleWidgetTest.php index ad32775918499c42a7667a7bb82734a4c2b6e07a..69d83975a0b7708cab69c1d4a4f60b949cb9031d 100644 --- a/web/modules/inline_entity_form/tests/src/FunctionalJavascript/SimpleWidgetTest.php +++ b/web/modules/inline_entity_form/tests/src/FunctionalJavascript/SimpleWidgetTest.php @@ -239,7 +239,7 @@ public function testEntityWithoutBundle() { * @param int $cardinality * The field cardinality with which to check. */ - protected function checkEditAccess(NodeInterface $host_node, $number_of_items, $cardinality) { + protected function checkEditAccess(NodeInterface $host_node, int $number_of_items, int $cardinality) { $assert_session = $this->assertSession(); $page = $this->getSession()->getPage(); $other_user = $this->createUser([ diff --git a/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldInstanceTest.php b/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldInstanceTest.php index 95a990f7fd49b2b6e7899607ff57e0c49c485980..a321e849acee0cb0b224ac7083e03795e1125ea0 100644 --- a/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldInstanceTest.php +++ b/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldInstanceTest.php @@ -49,7 +49,7 @@ protected function setUp(): void { * Whether or not the field is expected to be translatable. */ protected function assertEntity($id, $expected_label, $expected_field_type, $is_required, $expected_translatable) { - list ($expected_entity_type, $expected_bundle, $expected_name) = explode('.', $id); + [$expected_entity_type, $expected_bundle, $expected_name] = explode('.', $id); /** @var \Drupal\field\FieldConfigInterface $field */ $field = FieldConfig::load($id); @@ -93,8 +93,14 @@ public function testFieldInstances() { $this->assertEntity('node.test.field_single', 'single', 'entity_reference', FALSE, FALSE); $this->assertEntity('node.test.field_multiple', 'multiple', 'entity_reference', FALSE, FALSE); - $this->assertEntityReferenceFields('node.test.field_single', ['page'], ['field' => 'language', 'direction' => 'DESC']); - $this->assertEntityReferenceFields('node.test.field_multiple', ['page', 'test'], ['field' => '_none', 'direction' => 'ASC']); + $this->assertEntityReferenceFields( + 'node.test.field_single', + ['page'], ['field' => 'language', 'direction' => 'DESC'] + ); + $this->assertEntityReferenceFields( + 'node.test.field_multiple', + ['page', 'test'], ['field' => '_none', 'direction' => 'ASC'] + ); } } diff --git a/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldInstanceWidgetSettingsTest.php b/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldInstanceWidgetSettingsTest.php index 143babadbc5074f6ee5dae4d67a375b47abd5f69..3e059a420f34cfaf433788b6978635e3ed2f1c57 100644 --- a/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldInstanceWidgetSettingsTest.php +++ b/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldInstanceWidgetSettingsTest.php @@ -24,7 +24,7 @@ class MigrateFieldInstanceWidgetSettingsTest extends MigrateTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installConfig('node'); $this->installEntitySchema('node'); @@ -50,8 +50,8 @@ protected function assertEntity($id, $expected_entity_type, $expected_bundle) { /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity */ $entity = EntityFormDisplay::load($id); $this->assertInstanceOf(EntityFormDisplayInterface::class, $entity); - $this->assertIdentical($expected_entity_type, $entity->getTargetEntityTypeId()); - $this->assertIdentical($expected_bundle, $entity->getTargetBundle()); + $this->assertSame($expected_entity_type, $entity->getTargetEntityTypeId()); + $this->assertSame($expected_bundle, $entity->getTargetBundle()); } /** @@ -69,8 +69,8 @@ protected function assertEntity($id, $expected_entity_type, $expected_bundle) { protected function assertComponent($display_id, $component_id, $widget_type, $weight) { $component = EntityFormDisplay::load($display_id)->getComponent($component_id); $this->assertIsArray($component); - $this->assertIdentical($widget_type, $component['type']); - $this->assertIdentical($weight, $component['weight']); + $this->assertSame($widget_type, $component['type']); + $this->assertSame($weight, $component['weight']); } /** diff --git a/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldTest.php b/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldTest.php index f71dbd660444b18747b52e4d8607bbadd0c7e16f..928e79d7f78e14f28aee4207f75aced18f8da351 100644 --- a/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldTest.php +++ b/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateFieldTest.php @@ -23,7 +23,7 @@ class MigrateFieldTest extends MigrateTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->executeMigration('d7_field'); } @@ -41,7 +41,7 @@ protected function setUp() { * The expected cardinality of the field. */ protected function assertEntity($id, $expected_type, $expected_translatable, $expected_cardinality) { - list ($expected_entity_type, $expected_name) = explode('.', $id); + [$expected_entity_type, $expected_name] = explode('.', $id); /** @var \Drupal\field\FieldStorageConfigInterface $field */ $field = FieldStorageConfig::load($id); diff --git a/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateTestBase.php b/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateTestBase.php index 25cd2fa7c4ddaf4d5ab9e1bca3e808170181176c..5970ef8716e65af67d460fb682a16b25a5d2f16e 100644 --- a/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateTestBase.php +++ b/web/modules/inline_entity_form/tests/src/Kernel/Migrate/MigrateTestBase.php @@ -12,7 +12,7 @@ abstract class MigrateTestBase extends MigrateDrupalTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->loadFixture($this->getFixtureFilePath()); }