/**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     if ($this->entity->isNew()) {
         drupal_set_message($this->t('A layout has not yet been configured for this entity. To enable the entity layout for this entity you must configure the settings and default blocks for this entity layout.'), 'warning');
     }
     $target_entity_type = $this->entity->getTargetEntityType();
     $target_bundle = $this->entity->getTargetBundle();
     $bundle_entity_type = $this->entityLayoutService->getTargetBundleEntityType($this->entity);
     $form['text'] = ['#markup' => '<p>' . $this->t('This page will allow you to manage the default layout for when a @bundle is displayed. This may also be configured at the content entity level to override specific content entities.', ['@bundle' => $this->entityLayoutService->getTargetBundleLabel($this->entity)]) . '</p>'];
     $form['add_block_button'] = array('#type' => 'link', '#title' => $this->t('Place block'), '#url' => Url::fromRoute("entity_layout.{$target_entity_type}.block.library", [$bundle_entity_type => $target_bundle]), '#attributes' => ['class' => ['use-ajax', 'button', 'button--small'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 700])]);
     $form['layout'] = ['#type' => 'table', '#header' => [$this->t('Block'), $this->t('Category'), $this->t('Weight'), $this->t('Actions')], '#empty' => $this->t('No block have been placed for this entity layout.'), '#attributes' => ['class' => ['entity-layout-overview'], 'id' => 'entity-layout-overview'], '#tabledrag' => [['action' => 'order', 'relationship' => 'sibling', 'group' => 'block-weight']]];
     $blocks = $this->entity->getDefaultBlocks();
     // Weights range from -delta to +delta, so delta should be at least half
     // of the amount of blocks present. This makes sure all blocks in the same
     // region get an unique weight.
     $weight_delta = round(count($blocks) / 2);
     // Block rows.
     foreach ($blocks as $block_id => $block) {
         $form['layout'][$block_id] = $this->buildBlockRow($block, $weight_delta, $target_entity_type, $bundle_entity_type, $target_bundle);
     }
     $form['allowed_blocks'] = array('#type' => 'details', '#title' => $this->t('Allowed blocks'), '#tree' => TRUE);
     foreach ($this->entityLayoutService->getSystemBlocks() as $block_id => $block) {
         $form['allowed_blocks'][$block_id] = ['#type' => 'checkbox', '#title' => $block['admin_label'], '#default_value' => $this->entity->blockIsAllowed($block_id)];
     }
     $form['actions'] = array('#type' => 'actions', 'submit' => ['#type' => 'submit', '#button_type' => 'primary', '#value' => $this->t('Save')]);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form_state->set('initialized', FALSE);
     // @todo Remove this when tab logic has been implemented.
     if ($this->entity->isNew()) {
         drupal_set_message($this->t('A default layout must be configured for this content to be able to edit the layout.'), 'warning');
         return $form;
     }
     // If the entity layout and content entity combination has content blocks
     // then consider this layout as initialized.
     if ($this->entityLayoutService->hasContentBlocks($this->entity, $this->contentEntity)) {
         $form_state->set('initialized', TRUE);
     }
     $form = parent::form($form, $form_state);
     // Do not render the full form if the layout has not been initialized.
     if ($form_state->get('initialized') === FALSE) {
         return $form;
     }
     $target_entity_type = $this->entity->getTargetEntityType();
     $target_bundle = $this->entity->getTargetBundle();
     $bundle_entity_type = $this->entityLayoutService->getTargetBundleEntityType($this->entity);
     $form['add_block_button'] = ['#type' => 'link', '#title' => $this->t('Place block'), '#url' => Url::fromRoute("entity_layout.{$target_entity_type}.content.block.library", [$target_entity_type => $this->contentEntity->id()]), '#attributes' => ['class' => ['use-ajax', 'button', 'button--small'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 700])]];
     $form['layout'] = ['#type' => 'table', '#header' => [$this->t('Block'), $this->t('Category'), $this->t('Weight'), $this->t('Actions')], '#empty' => $this->t('No block have been placed for this entity layout.'), '#attributes' => ['class' => ['entity-layout-overview'], 'id' => 'entity-layout-overview'], '#tabledrag' => [['action' => 'order', 'relationship' => 'sibling', 'group' => 'block-weight']]];
     $blocks = $this->entityLayoutService->getContentBlockCollection($this->contentEntity)->getSortedByWeight();
     // Weights range from -delta to +delta, so delta should be at least half
     // of the amount of blocks present. This makes sure all blocks in the same
     // region get an unique weight.
     $weight_delta = round(count($blocks) / 2);
     foreach ($blocks as $block_id => $block) {
         $form['layout'][$block_id] = $this->buildBlockRow($block, $weight_delta, $target_entity_type, $bundle_entity_type, $target_bundle);
     }
     return $form;
 }