/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); $storage = $this->entityManager->getStorage('taxonomy_vocabulary'); $vocabulary = $storage->load($this->entity->bundle()); // @todo Move to storage http://drupal.org/node/1988712 taxonomy_check_vocabulary_hierarchy($vocabulary, array('tid' => $this->entity->id())); }
/** * {@inheritdoc} */ public function submit(array $form, array &$form_state) { $this->entity->delete(); $storage = $this->entityManager->getStorage('taxonomy_vocabulary'); $vocabulary = $storage->load($this->entity->bundle()); // @todo Move to storage http://drupal.org/node/1988712 taxonomy_check_vocabulary_hierarchy($vocabulary, array('tid' => $this->entity->id())); drupal_set_message($this->t('Deleted term %name.', array('%name' => $this->entity->getName()))); watchdog('taxonomy', 'Deleted term %name.', array('%name' => $this->entity->getName()), WATCHDOG_NOTICE); $form_state['redirect_route'] = $this->getCancelUrl(); }
/** * {@inheritdoc} */ public function submit(array $form, FormStateInterface $form_state) { $this->entity->delete(); $storage = $this->entityManager->getStorage('taxonomy_vocabulary'); $vocabulary = $storage->load($this->entity->bundle()); // @todo Move to storage http://drupal.org/node/1988712 taxonomy_check_vocabulary_hierarchy($vocabulary, array('tid' => $this->entity->id())); drupal_set_message($this->t('Deleted term %name.', array('%name' => $this->entity->getName()))); $this->logger('taxonomy')->notice('Deleted term %name.', array('%name' => $this->entity->getName())); $form_state->setRedirectUrl($this->getCancelUrl()); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); /** @var \Drupal\Core\Entity\ContentEntityInterface $term */ $term = $this->getEntity(); if ($term->isDefaultTranslation()) { $storage = $this->entityManager->getStorage('taxonomy_vocabulary'); $vocabulary = $storage->load($this->entity->bundle()); // @todo Move to storage http://drupal.org/node/1988712 taxonomy_check_vocabulary_hierarchy($vocabulary, array('tid' => $term->id())); } }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $term = $this->entity; $result = $term->save(); $link = $term->link($this->t('Edit'), 'edit-form'); switch ($result) { case SAVED_NEW: drupal_set_message($this->t('Created new term %term.', array('%term' => $term->getName()))); $this->logger('taxonomy')->notice('Created new term %term.', array('%term' => $term->getName(), 'link' => $link)); break; case SAVED_UPDATED: drupal_set_message($this->t('Updated term %term.', array('%term' => $term->getName()))); $this->logger('taxonomy')->notice('Updated term %term.', array('%term' => $term->getName(), 'link' => $link)); break; } $current_parent_count = count($form_state->getValue('parent')); $previous_parent_count = count($form_state->get(['taxonomy', 'parent'])); // Root doesn't count if it's the only parent. if ($current_parent_count == 1 && $form_state->hasValue(array('parent', 0))) { $current_parent_count = 0; $form_state->setValue('parent', array()); } // If the number of parents has been reduced to one or none, do a check on the // parents of every term in the vocabulary value. $vocabulary = $form_state->get(['taxonomy', 'vocabulary']); if ($current_parent_count < $previous_parent_count && $current_parent_count < 2) { taxonomy_check_vocabulary_hierarchy($vocabulary, $form_state->getValues()); } elseif ($current_parent_count > $previous_parent_count && $vocabulary->getHierarchy() != TAXONOMY_HIERARCHY_MULTIPLE) { $vocabulary->setHierarchy($current_parent_count == 1 ? TAXONOMY_HIERARCHY_SINGLE : TAXONOMY_HIERARCHY_MULTIPLE); $vocabulary->save(); } $form_state->setValue('tid', $term->id()); $form_state->set('tid', $term->id()); }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $term = $this->entity; switch ($term->save()) { case SAVED_NEW: drupal_set_message($this->t('Created new term %term.', array('%term' => $term->getName()))); $this->logger('taxonomy')->notice('Created new term %term.', array('%term' => $term->getName(), 'link' => l($this->t('Edit'), 'taxonomy/term/' . $term->id() . '/edit'))); break; case SAVED_UPDATED: drupal_set_message($this->t('Updated term %term.', array('%term' => $term->getName()))); $this->logger('taxonomy')->notice('Updated term %term.', array('%term' => $term->getName(), 'link' => l($this->t('Edit'), 'taxonomy/term/' . $term->id() . '/edit'))); break; } $current_parent_count = count($form_state['values']['parent']); $previous_parent_count = count($form_state['taxonomy']['parent']); // Root doesn't count if it's the only parent. if ($current_parent_count == 1 && isset($form_state['values']['parent'][0])) { $current_parent_count = 0; $form_state['values']['parent'] = array(); } // If the number of parents has been reduced to one or none, do a check on the // parents of every term in the vocabulary value. if ($current_parent_count < $previous_parent_count && $current_parent_count < 2) { taxonomy_check_vocabulary_hierarchy($form_state['taxonomy']['vocabulary'], $form_state['values']); } elseif ($current_parent_count > $previous_parent_count && $form_state['taxonomy']['vocabulary']->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE) { $form_state['taxonomy']['vocabulary']->hierarchy = $current_parent_count == 1 ? TAXONOMY_HIERARCHY_SINGLE : TAXONOMY_HIERARCHY_MULTIPLE; $form_state['taxonomy']['vocabulary']->save(); } $form_state['values']['tid'] = $term->id(); $form_state['tid'] = $term->id(); }