"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.9/core/modules/layout_builder/src/Controller/LayoutBuilderHtmlEntityFormController.php" (18 Nov 2020, 2010 Bytes) of package /linux/www/drupal-8.9.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "LayoutBuilderHtmlEntityFormController.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 9.0.8_vs_9.1.0-rc1.

    1 <?php
    2 
    3 namespace Drupal\layout_builder\Controller;
    4 
    5 use Drupal\Component\Utility\NestedArray;
    6 use Drupal\Core\Controller\FormController;
    7 use Drupal\Core\DependencyInjection\DependencySerializationTrait;
    8 use Drupal\Core\Routing\RouteMatchInterface;
    9 use Symfony\Component\HttpFoundation\Request;
   10 
   11 /**
   12  * Overrides the entity form controller service for layout builder operations.
   13  */
   14 class LayoutBuilderHtmlEntityFormController {
   15 
   16   use DependencySerializationTrait;
   17 
   18   /**
   19    * The entity form controller being decorated.
   20    *
   21    * @var \Drupal\Core\Controller\FormController
   22    */
   23   protected $entityFormController;
   24 
   25   /**
   26    * Constructs a LayoutBuilderHtmlEntityFormController object.
   27    *
   28    * @param \Drupal\Core\Controller\FormController $entity_form_controller
   29    *   The entity form controller being decorated.
   30    */
   31   public function __construct(FormController $entity_form_controller) {
   32     $this->entityFormController = $entity_form_controller;
   33   }
   34 
   35   /**
   36    * {@inheritdoc}
   37    */
   38   public function getContentResult(Request $request, RouteMatchInterface $route_match) {
   39     $form = $this->entityFormController->getContentResult($request, $route_match);
   40 
   41     // If the form render element has a #layout_builder_element_keys property,
   42     // first set the form element as a child of the root render array. Use the
   43     // keys to get the layout builder element from the form render array and
   44     // copy it to a separate child element of the root element to prevent any
   45     // forms within the layout builder element from being nested.
   46     if (isset($form['#layout_builder_element_keys'])) {
   47       $build['form'] = &$form;
   48       $layout_builder_element = &NestedArray::getValue($form, $form['#layout_builder_element_keys']);
   49       $build['layout_builder'] = $layout_builder_element;
   50       // Remove the layout builder element within the form.
   51       $layout_builder_element = [];
   52       return $build;
   53     }
   54 
   55     // If no #layout_builder_element_keys property, return form as is.
   56     return $form;
   57   }
   58 
   59 }