commit 2510ed21913398f1bd69b537b2e3865aaef71a01 Author: Lee Rowlands Date: Tue Jan 2 11:35:42 2018 +1000 p112 (cherry picked from commit 377cbf5f1d1fa9689f03e0ef3799a8447db63294) diff --git a/src/Form/EntityCloneForm.php b/src/Form/EntityCloneForm.php index 645506a..fba8c03 100644 --- a/src/Form/EntityCloneForm.php +++ b/src/Form/EntityCloneForm.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\TranslationManager; use Drupal\entity_clone\Event\EntityCloneEvent; @@ -130,6 +131,8 @@ class EntityCloneForm extends FormBase { $form = array_merge($form, $entity_clone_form_handler->formElement($this->entity)); } + $form['description']['#access'] = $this->descriptionShouldBeShown($form); + $form['clone'] = [ '#type' => 'submit', '#value' => 'Clone', @@ -209,4 +212,30 @@ class EntityCloneForm extends FormBase { } } + /** + * Checks if description should be shown. + * + * If there are no recursive elements visible, the description should be + * hidden. + * + * @param array $form + * Form. + * + * @return bool + * TRUE if description should be shown + */ + protected function descriptionShouldBeShown(array $form) { + $show_description = TRUE; + if (!isset($form['recursive'])) { + $show_description = FALSE; + } + $visible = array_filter(Element::children($form['recursive']), function ($key) use ($form) { + return !empty($form['recursive'][$key]['#access']); + }); + if (!$visible) { + $show_description = FALSE; + } + return $show_description; + } + }