You are here

class NodeInlineEntityFormController in Inline Entity Form 7

@file Defines the inline entity form controller for Nodes.

Hierarchy

Expanded class hierarchy of NodeInlineEntityFormController

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

File

includes/node.inline_entity_form.inc, line 8
Defines the inline entity form controller for Nodes.

View source
class NodeInlineEntityFormController extends EntityInlineEntityFormController {

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

  /**
   * Overrides EntityInlineEntityFormController::tableFields().
   */
  public function tableFields($bundles) {
    $fields = parent::tableFields($bundles);
    $fields['status'] = array(
      'type' => 'property',
      'label' => t('Status'),
      'weight' => 100,
    );
    return $fields;
  }

  /**
   * Overrides EntityInlineEntityFormController::entityForm().
   */
  public function entityForm($entity_form, &$form_state) {
    $node = $entity_form['#entity'];
    $type = node_type_get_type($node);
    $extra_fields = field_info_extra_fields('node', $node->type, 'form');

    // Do some prep work on the node, similarly to node_form().
    if (!isset($node->title)) {
      $node->title = NULL;
    }
    node_object_prepare($node);
    $entity_form['title'] = array(
      '#type' => 'textfield',
      '#title' => check_plain($type->title_label),
      '#required' => TRUE,
      '#default_value' => $node->title,
      '#maxlength' => 255,
      // The label might be missing if the Title module has replaced it.
      '#weight' => !empty($extra_fields['title']) ? $extra_fields['title']['weight'] : -5,
    );
    $entity_form['status'] = array(
      '#type' => 'radios',
      '#access' => user_access('administer nodes'),
      '#title' => t('Status'),
      '#default_value' => $node->status,
      '#options' => array(
        1 => t('Published'),
        0 => t('Unpublished'),
      ),
      '#required' => TRUE,
      '#weight' => 99,
    );
    $langcode = entity_language('node', $node);
    field_attach_form('node', $node, $entity_form, $form_state, $langcode);
    return $entity_form;
  }

  /**
   * Overrides EntityInlineEntityFormController::entityFormSubmit().
   */
  public function entityFormSubmit(&$entity_form, &$form_state) {
    parent::entityFormSubmit($entity_form, $form_state);
    node_submit($entity_form['#entity']);
    $child_form_state = form_state_defaults();
    $child_form_state['values'] = drupal_array_get_nested_value($form_state['values'], $entity_form['#parents']);
    foreach (module_implements('node_submit') as $module) {
      $function = $module . '_node_submit';
      $function($entity_form['#entity'], $entity_form, $child_form_state);
    }
  }

  /**
   * Overrides EntityInlineEntityFormController::createClone().
   */
  public function createClone($entity) {
    global $user;
    $cloned_entity = parent::createClone($entity);
    $cloned_entity->tnid = NULL;
    $cloned_entity->name = isset($user->name) ? $user->name : NULL;
    $cloned_entity->path = NULL;
    return $cloned_entity;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityInlineEntityFormController::$entityType protected property
EntityInlineEntityFormController::$settings public property
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::save public function Permanently saves the given entity. 2
EntityInlineEntityFormController::settingsForm public function Returns the settings form for the current entity type. 2
EntityInlineEntityFormController::__construct public function 1
NodeInlineEntityFormController::createClone public function Overrides EntityInlineEntityFormController::createClone(). Overrides EntityInlineEntityFormController::createClone
NodeInlineEntityFormController::defaultLabels public function Overrides EntityInlineEntityFormController::defaultLabels(). Overrides EntityInlineEntityFormController::defaultLabels
NodeInlineEntityFormController::entityForm public function Overrides EntityInlineEntityFormController::entityForm(). Overrides EntityInlineEntityFormController::entityForm
NodeInlineEntityFormController::entityFormSubmit public function Overrides EntityInlineEntityFormController::entityFormSubmit(). Overrides EntityInlineEntityFormController::entityFormSubmit
NodeInlineEntityFormController::tableFields public function Overrides EntityInlineEntityFormController::tableFields(). Overrides EntityInlineEntityFormController::tableFields