You are here

class BiblioContributorInlineEntityFormController in Bibliography Module 7.3

@file Defines the inline entity form controller for Biblio contributor.

Hierarchy

Expanded class hierarchy of BiblioContributorInlineEntityFormController

1 string reference to 'BiblioContributorInlineEntityFormController'
biblio_entity_info in ./biblio.module
Implements hook_entity_info().

File

includes/biblio_contributor.inline_entity_form.inc, line 8
Defines the inline entity form controller for Biblio contributor.

View source
class BiblioContributorInlineEntityFormController extends EntityInlineEntityFormController {

  /**
   * Overrides EntityInlineEntityFormController::tableFields().
   */
  public function tableFields($bundles) {
    $fields = array();
    $fields['lastname'] = array(
      'type' => 'property',
      'label' => t('Last name'),
      'weight' => 1,
    );
    $fields['firstname'] = array(
      'type' => 'property',
      'label' => t('First name'),
      'weight' => 2,
    );
    $fields['initials'] = array(
      'type' => 'property',
      'label' => t('Initials'),
      'weight' => 3,
    );
    return $fields;
  }

  /**
   * Overrides EntityInlineEntityFormController::entityForm().
   */
  public function entityForm($entity_form, &$form_state) {
    $biblio_contributor = $entity_form['#entity'];
    $properties = array(
      'prefix',
      'firstname',
      'initials',
      'lastname',
      'suffix',
    );
    foreach ($properties as $property) {
      $biblio_contributor->{$property} = !empty($biblio_contributor->{$property}) ? $biblio_contributor->{$property} : '';
    }
    $entity_form['prefix'] = array(
      '#type' => 'textfield',
      '#title' => t('Prefix'),
      '#default_value' => $biblio_contributor->prefix,
      '#maxlength' => 128,
    );
    $entity_form['firstname'] = array(
      '#type' => 'textfield',
      '#title' => t('First name'),
      '#default_value' => $biblio_contributor->firstname,
      '#maxlength' => 128,
    );
    $entity_form['initials'] = array(
      '#type' => 'textfield',
      '#title' => t('Initials'),
      '#default_value' => $biblio_contributor->initials,
      '#maxlength' => 10,
    );
    $entity_form['lastname'] = array(
      '#type' => 'textfield',
      '#title' => t('Last name'),
      '#default_value' => $biblio_contributor->lastname,
      '#maxlength' => 128,
    );
    $entity_form['suffix'] = array(
      '#type' => 'textfield',
      '#title' => t('Suffix'),
      '#default_value' => $biblio_contributor->suffix,
      '#maxlength' => 128,
    );
    field_attach_form('biblio_contributor', $biblio_contributor, $entity_form, $form_state);

    // Add all fields to the main fieldset.
    foreach (field_info_instances('biblio_contributor', 'biblio_contributor') as $instance) {
      $entity_form[$instance['field_name']]['#fieldset'] = 'details';
    }
    return $entity_form;
  }

  /**
   * Returns the settings form for the current entity type.
   *
   * The settings form is embedded into the IEF widget settings form.
   * Settings are later injected into the controller through $this->settings.
   *
   * @param $field
   *   The definition of the reference field used by IEF.
   * @param $instance
   *   The definition of the reference field instance.
   */
  public function settingsForm($field, $instance) {
    $labels = $this
      ->labels();
    $form = array();
    $form['allow_existing'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow users to add existing @label.', array(
        '@label' => $labels['plural'],
      )),
      '#default_value' => $this->settings['allow_existing'],
    );
    $form['match_operator'] = array(
      '#type' => 'select',
      '#title' => t('Autocomplete matching'),
      '#default_value' => $this->settings['match_operator'],
      '#options' => array(
        'STARTS_WITH' => t('Starts with'),
        'CONTAINS' => t('Contains'),
      ),
      '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'),
      '#states' => array(
        'visible' => array(
          ':input[name="instance[widget][settings][type_settings][allow_existing]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );

    // The single widget doesn't offer autocomplete functionality.
    if ($instance['widget']['type'] == 'inline_entity_form_single') {
      $form['allow_existing']['#access'] = FALSE;
      $form['match_operator']['#access'] = FALSE;
    }
    return $form;
  }

  /**
   * Overrides \EntityInlineEntityFormController::save()
   *
   * Add created and changed values.
   */
  public function save($entity, $context) {
    if (empty($entity->cid)) {
      $entity->created = REQUEST_TIME;
    }
    $entity->changed = REQUEST_TIME;
    parent::save($entity, $context);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BiblioContributorInlineEntityFormController::entityForm public function Overrides EntityInlineEntityFormController::entityForm(). Overrides EntityInlineEntityFormController::entityForm
BiblioContributorInlineEntityFormController::save public function Overrides \EntityInlineEntityFormController::save() Overrides EntityInlineEntityFormController::save
BiblioContributorInlineEntityFormController::settingsForm public function Returns the settings form for the current entity type. Overrides EntityInlineEntityFormController::settingsForm
BiblioContributorInlineEntityFormController::tableFields public function Overrides EntityInlineEntityFormController::tableFields(). Overrides EntityInlineEntityFormController::tableFields
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::defaultLabels public function Returns the default entity type labels. 2
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::entityFormSubmit public function Handles the submission of an entity form. 4
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::__construct public function 1