protected function InlineBlockUX::getNextInlineBlockNumber in Layout Builder UX 8
Gets the number of the next inline block.
Parameters
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
int The next number.
1 call to InlineBlockUX::getNextInlineBlockNumber()
- InlineBlockUX::buildConfigurationForm in src/
Plugin/ Block/ InlineBlockUX.php - Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements.
File
- src/
Plugin/ Block/ InlineBlockUX.php, line 72
Class
- InlineBlockUX
- Alters the inline block form.
Namespace
Drupal\lb_ux\Plugin\BlockCode
protected function getNextInlineBlockNumber(FormStateInterface $form_state) {
if ($form_state
->has('lb_ux.inline_block_count')) {
return $form_state
->get('lb_ux.inline_block_count');
}
/** @var \Drupal\layout_builder\SectionStorageInterface $section_storage */
$section_storage = $form_state
->getFormObject()
->getSectionStorage();
$count = $this->keyValueFactory
->get('lb_ux.inline_block_count.' . $section_storage
->getStorageType())
->get($section_storage
->getStorageId(), 0);
if (!$count) {
foreach ($section_storage
->getSections() as $section) {
foreach ($section
->getComponents() as $component) {
$plugin = $component
->getPlugin();
if ($plugin instanceof DerivativeInspectionInterface && $plugin
->getBaseId() === 'inline_block') {
$count++;
}
}
}
// Exclude the component being added.
if ($form_state
->has('layout_builder__component')) {
$count--;
}
}
$form_state
->set('lb_ux.inline_block_count', ++$count);
return $count;
}