public function ReusableBlocks::inlineBlockSubmit in Panopoly Magic 8.2
Submission callback for inline_block plugins.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Throws
\Drupal\Component\Plugin\Exception\PluginException
\Drupal\Core\Entity\EntityStorageException
File
- src/
Alterations/ ReusableBlocks.php, line 248
Class
- ReusableBlocks
- A service for altering some Layout Builder forms to allow reusable blocks.
Namespace
Drupal\panopoly_magic\AlterationsCode
public function inlineBlockSubmit(array $form, FormStateInterface $form_state) {
if (!$form_state
->getValue('reusable')) {
return;
}
/** @var \Drupal\layout_builder\SectionComponent $component */
$component = $form_state
->get('panopoly_magic__component');
/** @var \Drupal\layout_builder\SectionStorageInterface $section_storage */
$section_storage = $form_state
->get('panopoly_magic__section_storage');
$delta = $form_state
->get('panopoly_magic__delta');
$uuid = $form_state
->get('panopoly_magic__uuid');
/** @var \Drupal\Core\Block\BlockPluginInterface $block */
$block = $component
->getPlugin();
$configuration = $block
->getConfiguration();
/** @var \Drupal\block_content\BlockContentInterface $block_content */
$block_content = $form['settings']['block_form']['#block'];
$block_content
->setReusable();
$block_content
->setInfo($form_state
->getValue('info'));
$block_content
->save();
$block = $this->blockManager
->createInstance('block_content:' . $block_content
->uuid(), [
'view_mode' => $configuration['view_mode'],
'label' => $configuration['label'],
]);
$configuration = $block
->getConfiguration();
$section = $section_storage
->getSection($delta);
$section
->getComponent($uuid)
->setConfiguration($configuration);
$this->layoutTempstoreRepository
->set($section_storage);
}