You are here

protected function FormEntityHelperTrait::getEntityFromFormState in Block Style Plugins 8.2

Get the config entity of the entity being styled 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|\Drupal\layout_builder\Section The entity for the current Block, SectionComponent, or Section.

File

src/FormEntityHelperTrait.php, line 92

Class

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

Namespace

Drupal\block_style_plugins

Code

protected function getEntityFromFormState(FormStateInterface $form_state) {

  // Try to get a block/component entity.
  $entity = $this
    ->getBlockConfigEntityFromFormState($form_state);

  // Try to get a section entity if this is not a block.
  if (!$entity) {
    $entity = $this
      ->getSectionFromFormState($form_state);
  }
  return $entity;
}