You are here

class RedHenContactInlineEntityFormController in RedHen CRM 7

Class RedHenContactInlineEntityFormController.

Hierarchy

Expanded class hierarchy of RedHenContactInlineEntityFormController

1 string reference to 'RedHenContactInlineEntityFormController'
redhen_contact_entity_info in modules/redhen_contact/redhen_contact.module
Implements hook_entity_info().

File

modules/redhen_contact/lib/redhen_contact.inline_entity_form.inc, line 11
Defines the inline entity form controller for RedHen contacts.

View source
class RedHenContactInlineEntityFormController extends EntityInlineEntityFormController {

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

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

    // Do some prep work on the contact, similarly to node_form().
    if (!isset($contact->first_name)) {
      $contact->first_name = NULL;
    }
    if (!isset($contact->last_name)) {
      $contact->last_name = NULL;
    }
    $entity_form['name'] = array();
    $entity_form['name']['first_name'] = array(
      '#type' => 'textfield',
      '#title' => t('First name'),
      '#default_value' => $contact->first_name,
      '#maxlength' => 255,
      '#required' => TRUE,
      '#weight' => -6,
    );
    $entity_form['name']['middle_name'] = array(
      '#type' => 'textfield',
      '#title' => t('Middle name'),
      '#default_value' => $contact->middle_name,
      '#maxlength' => 255,
      '#weight' => -6,
    );
    $entity_form['name']['last_name'] = array(
      '#type' => 'textfield',
      '#title' => t('Last name'),
      '#default_value' => $contact->last_name,
      '#maxlength' => 255,
      '#required' => TRUE,
      '#weight' => 5,
    );
    field_attach_form('redhen_contact', $contact, $entity_form, $form_state);
    return $entity_form;
  }

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

    // Save default parameters back into the $contact object.
    $contact->first_name = $contact->name['first_name'];
    $contact->last_name = $contact->name['last_name'];

    // Set the contact's author uid.
    global $user;
    $contact->author_uid = $user->uid;

    // Get form_state array, only including the subform of this entity.
    $child_form_state = form_state_defaults();
    $child_form_state['values'] = drupal_array_get_nested_value($form_state['values'], $entity_form['#parents']);

    // Save the contact.
    $contact = redhen_contact_save($contact);
  }

}

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::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::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::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::save public function Permanently saves the given entity. 2
EntityInlineEntityFormController::settingsForm public function Returns the settings form for the current entity type. 2
EntityInlineEntityFormController::tableFields public function Returns an array of fields used to represent an entity in the IEF table. 4
EntityInlineEntityFormController::__construct public function 1
RedHenContactInlineEntityFormController::entityForm public function Overrides EntityInlineEntityFormController::entityForm(). Overrides EntityInlineEntityFormController::entityForm
RedHenContactInlineEntityFormController::entityFormSubmit public function Overrides EntityInlineEntityFormController::entityFormSubmit(). Overrides EntityInlineEntityFormController::entityFormSubmit
RedHenContactInlineEntityFormController::labels public function Overrides EntityInlineEntityFormController::labels(). Overrides EntityInlineEntityFormController::labels