You are here

class TaxonomyTermInlineEntityFormController in Inline Entity Form 7

@file Defines the inline entity form controller for Taxonomy terms.

Hierarchy

Expanded class hierarchy of TaxonomyTermInlineEntityFormController

1 string reference to 'TaxonomyTermInlineEntityFormController'
inline_entity_form_entity_info_alter in ./inline_entity_form.module
Implements hook_entity_info_alter().

File

includes/taxonomy_term.inline_entity_form.inc, line 8
Defines the inline entity form controller for Taxonomy terms.

View source
class TaxonomyTermInlineEntityFormController extends EntityInlineEntityFormController {

  /**
   * Overrides EntityInlineEntityFormController::defaultLabels().
   */
  public function defaultLabels() {
    $labels = array(
      'singular' => t('term'),
      'plural' => t('terms'),
    );
    return $labels;
  }

  /**
   * Overrides EntityInlineEntityFormController::tableFields().
   *
   * We can't use the parent class method because the taxonomy term metadata
   * wrapper doesn't have a property that matches the entity bundle key.
   * @todo: Remove this method once http://drupal.org/node/1662558 is fixed.
   */
  public function tableFields($bundles) {
    $fields = array();
    $info = entity_get_info($this->entityType);
    $metadata = entity_get_property_info($this->entityType);
    $label_key = $info['entity keys']['label'];
    $fields[$label_key] = array(
      'type' => 'property',
      'label' => $metadata ? $metadata['properties'][$label_key]['label'] : t('Label'),
      'weight' => 1,
    );

    // Add the vocabulary type.
    $fields['vocabulary'] = array(
      'type' => 'property',
      'label' => t('Vocabulary'),
      'weight' => 2,
    );
    return $fields;
  }

  /**
   * Overrides EntityInlineEntityFormController::entityForm().
   */
  public function entityForm($entity_form, &$form_state) {
    $term = $entity_form['#entity'];
    $extra_fields = field_info_extra_fields('taxonomy_term', $term->vocabulary_machine_name, 'form');
    $defaults = array(
      'name' => '',
      'description' => '',
      'format' => NULL,
      'tid' => NULL,
      'weight' => 0,
    );
    foreach ($defaults as $key => $value) {
      if (!isset($term->{$key})) {
        $term->{$key} = $value;
      }
    }
    $entity_form['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Name'),
      '#default_value' => $term->name,
      '#maxlength' => 255,
      '#required' => TRUE,
      // The label might be missing if the Title module has replaced it.
      '#weight' => !empty($extra_fields['name']) ? $extra_fields['name']['weight'] : -5,
    );
    $entity_form['description'] = array(
      '#type' => 'text_format',
      '#title' => t('Description'),
      '#default_value' => $term->description,
      '#format' => $term->format,
      '#weight' => !empty($extra_fields['description']) ? $extra_fields['description']['weight'] : -4,
    );
    $langcode = entity_language('taxonomy_term', $term);
    field_attach_form('taxonomy_term', $term, $entity_form, $form_state, $langcode);
    return $entity_form;
  }

  /**
   * Overrides EntityInlineEntityFormController::entityFormSubmit().
   */
  public function entityFormSubmit(&$entity_form, &$form_state) {
    parent::entityFormSubmit($entity_form, $form_state);
    $entity = $entity_form['#entity'];

    // Set the vocabulary ID.
    $vocabularies = taxonomy_vocabulary_get_names();
    if (isset($vocabularies[$entity->vocabulary_machine_name])) {
      $entity->vid = $vocabularies[$entity->vocabulary_machine_name]->vid;
    }

    // Separate the description and format.
    $entity->format = $entity->description['format'];
    $entity->description = $entity->description['value'];
  }

  /**
   * Overrides EntityInlineEntityFormController::save().
   */
  public function save($entity, $context) {
    taxonomy_term_save($entity);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityInlineEntityFormController::$entityType protected property
EntityInlineEntityFormController::$settings public property
EntityInlineEntityFormController::createClone public function Creates a clone of the given entity. 2
EntityInlineEntityFormController::css public function Returns an array of css filepaths for the current entity type, keyed by theme name. 1
EntityInlineEntityFormController::defaultSettings public function Returns an array of default settings in the form of key => value. 2
EntityInlineEntityFormController::delete public function Delete permanently saved entities. 1
EntityInlineEntityFormController::entityFormValidate public function Validates the entity form. 2
EntityInlineEntityFormController::entityType public function Returns the entity type managed by this controller.
EntityInlineEntityFormController::getSetting public function Returns a setting value.
EntityInlineEntityFormController::labels public function Returns an array of entity type labels fit for display in the UI.
EntityInlineEntityFormController::removeForm public function Returns the remove form to be shown through the IEF widget. 1
EntityInlineEntityFormController::removeFormSubmit public function Handles the submission of a remove form. Decides what should happen to the entity after the removal confirmation.
EntityInlineEntityFormController::settingsForm public function Returns the settings form for the current entity type. 2
EntityInlineEntityFormController::__construct public function 1
TaxonomyTermInlineEntityFormController::defaultLabels public function Overrides EntityInlineEntityFormController::defaultLabels(). Overrides EntityInlineEntityFormController::defaultLabels
TaxonomyTermInlineEntityFormController::entityForm public function Overrides EntityInlineEntityFormController::entityForm(). Overrides EntityInlineEntityFormController::entityForm
TaxonomyTermInlineEntityFormController::entityFormSubmit public function Overrides EntityInlineEntityFormController::entityFormSubmit(). Overrides EntityInlineEntityFormController::entityFormSubmit
TaxonomyTermInlineEntityFormController::save public function Overrides EntityInlineEntityFormController::save(). Overrides EntityInlineEntityFormController::save
TaxonomyTermInlineEntityFormController::tableFields public function Overrides EntityInlineEntityFormController::tableFields(). Overrides EntityInlineEntityFormController::tableFields