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;
* 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) {
'override_labels' => FALSE,
'label_singular' => '',
'label_plural' => '',
+ 'collapsible' => FALSE,
+ 'collapsed' => FALSE,
];
}
],
],
];
+ $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;
}
$summary[] = $this->t('Default labels are used.');
}
+ if ($this->getSetting('collapsible')) {
+ $summary[] = $this->t($this->getSetting('collapsed') ? 'Collapsible, collapsed by default' : 'Collapsible');
+ }
+
return $summary;
}
* - 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
* @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)) {
* 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) {
/** @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']);