You are here

protected function FormEntityHelperTrait::getBlockConfigEntityFromFormState in Block Style Plugins 8.2

Get the Block config entity from the form state.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The current form state.

Return value

\Drupal\block\Entity\Block|\Drupal\layout_builder\SectionComponent The entity for the current Block or layout builder SectionComponent.

4 calls to FormEntityHelperTrait::getBlockConfigEntityFromFormState()
BlockFormAlter::alterForm in src/BlockFormAlter.php
Alter a form and set block configuration.
BlockFormAlter::submitForm in src/BlockFormAlter.php
Submit the form and save configuration.
FormEntityHelperTrait::getBlockContent in src/FormEntityHelperTrait.php
Get the Block Content entity.
FormEntityHelperTrait::getEntityFromFormState in src/FormEntityHelperTrait.php
Get the config entity of the entity being styled from the form state.

File

src/FormEntityHelperTrait.php, line 113

Class

FormEntityHelperTrait
Provides a helper for getting information from the entity being styled.

Namespace

Drupal\block_style_plugins

Code

protected function getBlockConfigEntityFromFormState(FormStateInterface $form_state) {

  /** @var Drupal\block\BlockForm $form_object */
  $form_object = $form_state
    ->getFormObject();
  $entity = NULL;

  // Get the current block config entity.
  if ($form_object instanceof UpdateBlockForm) {

    /** @var \Drupal\layout_builder\SectionComponent $entity */
    $entity = $form_object
      ->getCurrentComponent();
  }
  elseif ($form_object instanceof AddBlockForm) {

    /** @var \Drupal\layout_builder\SectionComponent $entity */
    $entity = $form_state
      ->get('layout_builder__component');
  }
  elseif ($form_object instanceof ConfigureStyles) {

    /** @var \Drupal\block_style_plugins\Form\ConfigureStyles $entity */
    $entity = $form_object
      ->getComponent();
  }
  elseif (method_exists($form_object, 'getEntity')) {

    /** @var \Drupal\block\Entity\Block $entity */
    $entity = $form_object
      ->getEntity();
  }
  return $entity;
}