X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Finline_entity_form%2Fsrc%2FPlugin%2FField%2FFieldWidget%2FInlineEntityFormBase.php;h=1e69c7c9fb42683f9043c83a1d7b0768e3af1893;hp=123b58fc65f3355bad1f15a4b2631873388c968f;hb=059867c3f96750652c80f39e44c442a58c2549ee;hpb=f8fc16ae6b862bef59baaad5d051dd37b7ff11b2 diff --git a/web/modules/contrib/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php b/web/modules/contrib/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php index 123b58fc6..1e69c7c9f 100644 --- a/web/modules/contrib/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php +++ b/web/modules/contrib/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php @@ -2,7 +2,6 @@ namespace Drupal\inline_entity_form\Plugin\Field\FieldWidget; -use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; @@ -72,7 +71,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto * The entity type bundle info. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. - * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface + * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository * The entity display repository. */ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) { @@ -194,6 +193,8 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto 'override_labels' => FALSE, 'label_singular' => '', 'label_plural' => '', + 'collapsible' => FALSE, + 'collapsed' => FALSE, ]; } @@ -236,6 +237,21 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto ], ], ]; + $element['collapsible'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Collapsible'), + '#default_value' => $this->getSetting('collapsible'), + ]; + $element['collapsed'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Collapsed by default'), + '#default_value' => $this->getSetting('collapsed'), + '#states' => [ + 'visible' => [ + ':input[name="' . $states_prefix . '[collapsible]"]' => ['checked' => TRUE], + ], + ], + ]; return $element; } @@ -262,6 +278,10 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto $summary[] = $this->t('Default labels are used.'); } + if ($this->getSetting('collapsible')) { + $summary[] = $this->t($this->getSetting('collapsed') ? 'Collapsible, collapsed by default' : 'Collapsible'); + } + return $summary; } @@ -291,7 +311,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto * - Is IEF handler loaded? * - Are we on a "real" entity form and not on default value widget? * - * @param FormStateInterface $form_state + * @param \Drupal\Core\Form\FormStateInterface $form_state * Form state. * * @return bool @@ -404,7 +424,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto * @return bool * TRUE if translating is in progress, FALSE otherwise. * - * @see \Drupal\inline_entity_form\TranslationHelper::initFormLangcodes(). + * @see \Drupal\inline_entity_form\TranslationHelper::initFormLangcodes() */ protected function isTranslating(FormStateInterface $form_state) { if (TranslationHelper::isTranslating($form_state)) { @@ -453,8 +473,8 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto * still decide to cancel the parent form. * * @param $entity_form - * The form of the entity being managed inline. - * @param $form_state + * 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) { @@ -462,7 +482,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto /** @var \Drupal\Core\Entity\EntityInterface $entity */ $entity = $entity_form['#entity']; - if ($entity_form['#op'] == 'add') { + if (in_array($entity_form['#op'], ['add', 'duplicate'])) { // Determine the correct weight of the new element. $weight = 0; $entities = $form_state->get(['inline_entity_form', $ief_id, 'entities']);