class VocabularyFormController extends EntityFormController {
public function form(array $form, array &$form_state) {
$vocabulary = $this->entity;
if (isset($form_state['confirm_delete']) && isset($form_state['values']['vid'])) {
return taxonomy_vocabulary_confirm_delete($form, $form_state, $form_state['values']['vid']);
}
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $vocabulary->name,
'#maxlength' => 255,
'#required' => TRUE,
);
$form['vid'] = array(
'#type' => 'machine_name',
'#default_value' => $vocabulary
->id(),
'#maxlength' => 255,
'#machine_name' => array(
'exists' => 'taxonomy_vocabulary_load',
'source' => array(
'name',
),
),
);
$form['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#default_value' => $vocabulary->description,
);
$form['langcode'] = array(
'#type' => 'language_select',
'#title' => t('Vocabulary language'),
'#languages' => Language::STATE_ALL,
'#default_value' => $vocabulary->langcode,
);
if (module_exists('language')) {
$form['default_terms_language'] = array(
'#type' => 'details',
'#title' => t('Terms language'),
);
$form['default_terms_language']['default_language'] = array(
'#type' => 'language_configuration',
'#entity_information' => array(
'entity_type' => 'taxonomy_term',
'bundle' => $vocabulary
->id(),
),
'#default_value' => language_get_default_configuration('taxonomy_term', $vocabulary
->id()),
);
}
$form['hierarchy'] = array(
'#type' => 'value',
'#value' => '0',
);
return parent::form($form, $form_state, $vocabulary);
}
protected function actions(array $form, array &$form_state) {
if (empty($form_state['confirm_delete'])) {
$actions = parent::actions($form, $form_state);
array_unshift($actions['delete']['#submit'], array(
$this,
'submit',
));
if (module_exists('language')) {
array_unshift($actions['submit']['#submit'], 'language_configuration_element_submit');
array_unshift($actions['submit']['#submit'], array(
$this,
'languageConfigurationSubmit',
));
}
if (module_exists('translation_entity')) {
array_unshift($actions['submit']['#submit'], 'translation_entity_language_configuration_element_submit');
}
return $actions;
}
else {
return array();
}
}
public function languageConfigurationSubmit(array &$form, array &$form_state) {
$vocabulary = $this->entity;
if ($vocabulary && $vocabulary
->id() && $vocabulary
->id() != $form_state['values']['vid']) {
language_clear_default_configuration('taxonomy_term', $vocabulary
->id());
}
$form_state['language']['default_language']['bundle'] = $form_state['values']['vid'];
}
public function submit(array $form, array &$form_state) {
if ($form_state['triggering_element']['#value'] == t('Delete')) {
$form_state['rebuild'] = TRUE;
$form_state['confirm_delete'] = TRUE;
return NULL;
}
else {
return parent::submit($form, $form_state);
}
}
public function save(array $form, array &$form_state) {
$vocabulary = $this->entity;
$vocabulary->name = trim($vocabulary->name);
switch ($vocabulary
->save()) {
case SAVED_NEW:
drupal_set_message(t('Created new vocabulary %name.', array(
'%name' => $vocabulary->name,
)));
watchdog('taxonomy', 'Created new vocabulary %name.', array(
'%name' => $vocabulary->name,
), WATCHDOG_NOTICE, l(t('edit'), 'admin/structure/taxonomy/manage/' . $vocabulary
->id() . '/edit'));
$form_state['redirect'] = 'admin/structure/taxonomy/manage/' . $vocabulary
->id();
break;
case SAVED_UPDATED:
drupal_set_message(t('Updated vocabulary %name.', array(
'%name' => $vocabulary->name,
)));
watchdog('taxonomy', 'Updated vocabulary %name.', array(
'%name' => $vocabulary->name,
), WATCHDOG_NOTICE, l(t('edit'), 'admin/structure/taxonomy/manage/' . $vocabulary
->id() . '/edit'));
$form_state['redirect'] = 'admin/structure/taxonomy';
break;
}
$form_state['values']['vid'] = $vocabulary
->id();
$form_state['vid'] = $vocabulary
->id();
}
}