You are here

class PartyDefaultDataSetUIAdd in Party 7

Same name and namespace in other branches
  1. 8.2 includes/party.data_ui.inc \PartyDefaultDataSetUIAdd

The 'add' action: attach a new entity.

@todo: not yet in use. See todo in party_menu().

Hierarchy

Expanded class hierarchy of PartyDefaultDataSetUIAdd

1 string reference to 'PartyDefaultDataSetUIAdd'
party_profile_party_data_set_info in modules/party_profile/party_profile.party_info.inc
Implements hook_party_data_set_info().

File

includes/party.data_ui.inc, line 70
Provides default classes for UI actions on data sets.

View source
class PartyDefaultDataSetUIAdd implements PartyDataSetActionInterface {

  /**
   * The page title for the action form.
   */
  function get_page_title($party, $data_set, $eid = NULL) {
    return t("Add new @data-set-label to @party-label", array(
      '@data-set-label' => $data_set['label'],
      '@party-label' => $party->label,
    ));
  }

  /**
   * Provides the action form for adding a new entity.
   *
   * @param $party
   *   A loaded party object.
   * @param $data_set
   *   A loaded data set.
   *   We don't actually need this loaded, but we need a menu loader to convert
   *   the path-style string to the machine name, and a menu loader that doesn't
   *   load would be weird too.
   * @param $eid
   *   The id of the entity, if relevant to this action.
   */
  function action_form($form, &$form_state, $party, $data_set, $eid = NULL) {
    $form = array();
    $form_state['#attached_entity'] = $party
      ->getDataSetController($data_set['set_name'])
      ->createEntity();
    field_attach_form($data_set['entity type'], $form_state['#attached_entity'], $form, $form_state);
    $form['actions'] = array(
      '#type' => 'actions',
      'submit' => array(
        '#type' => 'submit',
        '#value' => t('Create new @label', array(
          '@label' => $data_set['label'],
        )),
      ),
    );
    return $form;
  }
  function action_form_validate($form, &$form_state) {

    // Get the original form parameters.
    list($party, $data_set, $action, $eid) = $form_state['build_info']['args'];
    field_attach_form_validate($data_set['entity type'], $form_state['#attached_entity'], $form, $form_state);
  }
  function action_form_submit($form, &$form_state) {

    // Get the original form parameters.
    list($party, $data_set, $action, $eid) = $form_state['build_info']['args'];
    field_attach_submit($data_set['entity type'], $form_state['#attached_entity'], $form, $form_state);

    // Attach the entity and save the entity and controller.
    $party
      ->getDataSetController($data_set['set_name'])
      ->attachEntity($form_state['#attached_entity'])
      ->save(TRUE);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PartyDefaultDataSetUIAdd::action_form function Provides the action form for adding a new entity. Overrides PartyDataSetActionInterface::action_form 1
PartyDefaultDataSetUIAdd::action_form_submit function Form submission for the action form. Overrides PartyDataSetActionInterface::action_form_submit 1
PartyDefaultDataSetUIAdd::action_form_validate function Form validation for the action form. Overrides PartyDataSetActionInterface::action_form_validate 1
PartyDefaultDataSetUIAdd::get_page_title function The page title for the action form. Overrides PartyDataSetActionInterface::get_page_title