function organigrams_form_alter in Organigrams 8
Same name and namespace in other branches
- 8.2 organigrams.module \organigrams_form_alter()
Implements hook_form_alter().
File
- ./
organigrams.module, line 42 - Extends Taxonomy to create organigrams.
Code
function organigrams_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Alter the vocabulary form.
if ($form_id == 'taxonomy_vocabulary_form') {
// Get the vocabulary.
$vocabulary = $form_state
->getFormObject()
->getEntity();
// Get its organigrams settings if they exist.
$organigram = $vocabulary
->getThirdPartySettings('organigrams');
// Check if the current page is a vocabulary add form and if there are
// organigrams settings.
if (\Drupal::routeMatch()
->getRouteName() == 'entity.vocabulary.add_organigram_form' || !empty($organigram)) {
// Add our own submit function to the submit button.
foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
$form['actions'][$action]['#submit'][] = 'organigrams_vocabulary_form_submit';
}
}
// Change the form title when adding and editing.
if (!empty($organigram)) {
$form['#title'] = t('Edit organigram vocabulary');
}
else {
$form['#title'] = t('Add organigram vocabulary');
}
// Add organigrams settings fields to the form.
organigrams_vocabulary_settings_form($form, $organigram);
}
}
}