You are here

class MoveBlockForm in Layout Builder Restrictions 8.2

Provides a form for moving a block.

@internal Form classes are internal.

Hierarchy

Expanded class hierarchy of MoveBlockForm

File

src/Form/MoveBlockForm.php, line 17

Namespace

Drupal\layout_builder_restrictions\Form
View source
class MoveBlockForm extends MoveBlockFormCore {

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $to_region = $this
      ->getSelectedRegion($form_state);
    $to_delta = $this
      ->getSelectedDelta($form_state);
    $from_delta = $this->delta;

    // $original_section = $this->sectionStorage->getSection($from_delta);
    // $component = $original_section->getComponent($this->uuid);
    // Retrieve defined Layout Builder Restrictions plugins.
    $layout_builder_restrictions_manager = \Drupal::service('plugin.manager.layout_builder_restriction');
    $restriction_definitions = $layout_builder_restrictions_manager
      ->getDefinitions();
    foreach ($restriction_definitions as $restriction_definition) {

      // @todo: respect ordering of plugins (see #3045266)
      $plugin_instance = $layout_builder_restrictions_manager
        ->createInstancE($restriction_definition['id']);
      $block_status = $plugin_instance
        ->blockAllowedinContext($this->sectionStorage, $from_delta, $to_delta, $to_region, $this->uuid, NULL);
      if ($block_status !== TRUE) {
        $form_state
          ->setErrorByName('region', $block_status);
      }
    }
  }

  /**
   * Submit form dialog #ajax callback.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   *
   * @return \Drupal\Core\Ajax\AjaxResponse
   *   An AJAX response that display validation error messages or represents a
   *   successful submission.
   */
  public function ajaxSubmit(array &$form, FormStateInterface $form_state) {
    if ($form_state
      ->hasAnyErrors()) {
      $build_info = $form_state
        ->getBuildInfo();
      $response = new AjaxResponse();
      $content = "";
      foreach ($form_state
        ->getErrors() as $error) {
        $content .= '<p>' . $error . '</p>';
      }
      $build['error'] = [
        '#markup' => $content,
      ];
      $build['back_button'] = [
        '#type' => 'link',
        '#url' => Url::fromRoute('layout_builder.move_block_form', [
          'section_storage_type' => $build_info['args'][0]
            ->getPluginId(),
          'section_storage' => $build_info['args'][0]
            ->getStorageId(),
          'delta' => $build_info['args'][1],
          'region' => $build_info['args'][2],
          'uuid' => $build_info['args'][3],
        ]),
        '#title' => $this
          ->t('Back'),
        '#attributes' => [
          'class' => [
            'use-ajax',
          ],
          'data-dialog-type' => 'dialog',
          'data-dialog-renderer' => 'off_canvas',
        ],
      ];
      $response
        ->addCommand(new OpenOffCanvasDialogCommand("Content cannot be placed.", $build));
    }
    else {
      $response = $this
        ->successfulAjaxSubmit($form, $form_state);
    }
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AjaxHelperTrait::getRequestWrapperFormat protected function Gets the wrapper format of the current request.
AjaxHelperTrait::isAjax protected function Determines if the current request is via AJAX.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
LayoutBuilderHighlightTrait::blockAddHighlightId protected function Provides the ID used to highlight the active Layout Builder UI element.
LayoutBuilderHighlightTrait::blockUpdateHighlightId protected function Provides the ID used to highlight the active Layout Builder UI element.
LayoutBuilderHighlightTrait::sectionAddHighlightId protected function Provides the ID used to highlight the active Layout Builder UI element.
LayoutBuilderHighlightTrait::sectionUpdateHighlightId protected function Provides the ID used to highlight the active Layout Builder UI element.
LayoutRebuildTrait::rebuildAndClose protected function Rebuilds the layout.
LayoutRebuildTrait::rebuildLayout protected function Rebuilds the layout.
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
MoveBlockForm::$delta protected property The section delta.
MoveBlockForm::$layoutTempstore protected property The Layout Tempstore.
MoveBlockForm::$region protected property The region name.
MoveBlockForm::$sectionStorage protected property The section storage.
MoveBlockForm::$uuid protected property The component uuid.
MoveBlockForm::ajaxSubmit public function Submit form dialog #ajax callback. Overrides AjaxFormHelperTrait::ajaxSubmit
MoveBlockForm::buildForm public function Builds the move block form. Overrides FormInterface::buildForm
MoveBlockForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
MoveBlockForm::getComponentsWrapper public function Ajax callback for the region select element.
MoveBlockForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
MoveBlockForm::getSelectedDelta protected function Gets the selected delta.
MoveBlockForm::getSelectedRegion protected function Gets the selected region.
MoveBlockForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
MoveBlockForm::successfulAjaxSubmit protected function Allows the form to respond to a successful AJAX submission. Overrides AjaxFormHelperTrait::successfulAjaxSubmit
MoveBlockForm::title public function Provides a title callback.
MoveBlockForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
MoveBlockForm::__construct public function Constructs a new MoveBlockForm.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.