Last active
August 29, 2016 06:50
-
-
Save orakili/5874179 to your computer and use it in GitHub Desktop.
Drupal 7 - taxonomy_revision 1.4 - Show revisions block when creating a new term to allow adding initial log message.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/taxonomy_revision.module b/taxonomy_revision.module | |
index ea72297..a796522 100644 | |
--- a/taxonomy_revision.module | |
+++ b/taxonomy_revision.module | |
@@ -237,41 +237,55 @@ function taxonomy_revision_entity_info_alter(&$entity_info) { | |
* Implements hook_field_attach_form(). | |
*/ | |
function taxonomy_revision_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) { | |
- if ($entity_type == 'taxonomy_term' && !empty($entity->tid)) { | |
- $form['revision_information'] = array( | |
- '#type' => 'fieldset', | |
- '#title' => t('Revision information'), | |
- '#collapsible' => TRUE, | |
- '#weight' => 20, | |
- '#access' => user_access('choose taxonomy term revisions'), | |
- ); | |
- if (!_taxonomy_revision_enabled_by_default($entity->vid)) { | |
- $form['revision_information']['revision'] = array( | |
- '#type' => 'checkbox', | |
- '#title' => t('Create new revision'), | |
- ); | |
+ if ($entity_type == 'taxonomy_term') { | |
+ // Get the vocabulary id from the entity if defined. | |
+ if (!empty($entity->vid)) { | |
+ $vocabulary_id = $entity->vid; | |
} | |
- else { | |
- $form['revision_information']['revision'] = array( | |
- '#type' => 'markup', | |
- '#markup' => t('New revision will be created automatically.'), | |
- ); | |
+ // Otherwise load the vocabulary if the machine name is present. | |
+ elseif (isset($entity->vocabulary_machine_name)) { | |
+ $vocabulary = taxonomy_vocabulary_machine_name_load($entity->vocabulary_machine_name); | |
+ if (!empty($vocabulary->vid)) { | |
+ $vocabulary_id = $vocabulary->vid; | |
+ } | |
} | |
- $form['revision_information']['log'] = array( | |
- '#type' => 'textarea', | |
- '#title' => t('Revision log message'), | |
- '#rows' => 4, | |
- '#description' => t('Provide an explanation of the changes you are making. This will help other authors understand your motivations.'), | |
- ); | |
- if (!_taxonomy_revision_enabled_by_default($entity->vid)) { | |
- $form['revision_information']['log']['#states'] = array( | |
- 'invisible' => array( | |
- 'input[name="revision"]' => array('checked' => FALSE), | |
- ), | |
+ // Add the revision information to the form. | |
+ if (isset($vocabulary_id)) { | |
+ $form['revision_information'] = array( | |
+ '#type' => 'fieldset', | |
+ '#title' => t('Revision information'), | |
+ '#collapsible' => TRUE, | |
+ '#weight' => 20, | |
+ '#access' => user_access('administer taxonomy'), | |
); | |
- } | |
+ if (!_taxonomy_revision_enabled_by_default($vocabulary_id)) { | |
+ $form['revision_information']['revision'] = array( | |
+ '#type' => 'checkbox', | |
+ '#title' => t('Create new revision'), | |
+ ); | |
+ } | |
+ else { | |
+ $form['revision_information']['revision'] = array( | |
+ '#type' => 'markup', | |
+ '#markup' => t('New revision will be created automatically.'), | |
+ ); | |
+ } | |
+ $form['revision_information']['log'] = array( | |
+ '#type' => 'textarea', | |
+ '#title' => t('Revision log message'), | |
+ '#rows' => 4, | |
+ '#description' => t('Provide an explanation of the changes you are making. This will help other authors understand your motivations.'), | |
+ ); | |
+ if (!_taxonomy_revision_enabled_by_default($vocabulary_id)) { | |
+ $form['revision_information']['log']['#states'] = array( | |
+ 'invisible' => array( | |
+ 'input[name="revision"]' => array('checked' => FALSE), | |
+ ), | |
+ ); | |
+ } | |
- $form['#entity_builders'][] = 'taxonomy_revision_taxonomy_form_term_submit_build_term'; | |
+ $form['#entity_builders'][] = 'taxonomy_revision_taxonomy_form_term_submit_build_term'; | |
+ } | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment