/** * Submit handler for tab. */ public function tabSave($form, FormStateInterface $form_state) { $this->save($form, $form_state); // Check if this field has any configuration options. $tab = $this->tabManager->getDefinition($form_state->getValue('new')); // Load the configuration form for this option. if (is_subclass_of($tab['class'], '\Drupal\blocktabs\ConfigurableTabInterface')) { $form_state->setRedirect( 'blocktabs.tab_add_form', array( 'blocktabs' => $this->entity->id(), 'tab' => $form_state->getValue('new'), ), array('query' => array('weight' => $form_state->getValue('weight'))) ); } // If there's no form, immediately add the tab. else { $tab = array( 'id' => $tab['id'], 'data' => array(), 'weight' => $form_state->getValue('weight'), ); $tab_id = $this->entity->addTab($tab); $this->entity->save(); if (!empty($tab_id)) { drupal_set_message($this->t('The tab was successfully added.')); } } }
/** * {@inheritdoc} */ protected function prepareTab($tab) { $tab = $this->tabManager->createInstance($tab); // Set the initial weight so this tab comes last. $tab->setWeight(count($this->blocktabs->getTabs())); return $tab; }