You are here

class PartyActivityElementTitle in Party 7

Class to add the node title field to a form.

Hierarchy

Expanded class hierarchy of PartyActivityElementTitle

1 string reference to 'PartyActivityElementTitle'
party_activity_flexiform_element_info in modules/party_activity/party_activity.flexiform.inc
Implements hook_flexiform_element_info().

File

modules/party_activity/includes/element/party_activity_title.element.inc, line 10
Contains class for the Node title element.

View source
class PartyActivityElementTitle extends FlexiformElement {

  /**
   * Return the form element for this FlexiformElement.
   */
  public function form($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
    $parents = $form['#parents'];
    $parents[] = 'title';

    // Work out the default value.
    $default = '';
    if (!empty($this->settings['default_value']['default_value'])) {
      $default = $this->settings['default_value']['default_value'];
    }
    if (!empty($this->settings['default_value']['use_tokens'])) {
      $default = $this
        ->replaceCtoolsSubstitutions($default, $form['#flexiform_entities']);
    }
    $form[$this->element_namespace] = array(
      '#type' => 'textfield',
      '#parents' => $parents,
      '#title' => $this
        ->label(),
      '#required' => TRUE,
      '#default_value' => !empty($entity->title) ? $entity->title : $default,
      '#maxlength' => 255,
    );
    $form = parent::form($form, $form_state, $entity);
    return $form;
  }

  /**
   * Validate the form element.
   */
  public function formValidate($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
  }

  /**
   * Submit the form element.
   */
  public function formSubmit($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
    $title = $this
      ->formExtractValues($form, $form_state, $entity);
    $entity->title = $title;
  }

  /**
   * Extract the submitted values for this form element.
   */
  public function formExtractValues($form, &$form_state, $entity) {
    $parents = $form['#parents'];
    $parents[] = $this
      ->getEntityNamespace();
    $parents[] = 'title';
    $title = drupal_array_get_nested_value($form_state['values'], $parents);
    return $title;
  }

  /**
   * {@inheritdoc}
   */
  public function configureForm($form, &$form_state, $flexiform) {
    $form = parent::configureForm($form, $form_state, $flexiform);
    $form['default_value'] = array(
      '#tree' => TRUE,
      '#type' => 'fieldset',
      '#title' => t('Default Value'),
      '#weight' => -5,
    );
    $form['default_value']['default_value'] = array(
      '#type' => 'textfield',
      '#title' => $this
        ->label() ? $this
        ->label() : t('Default'),
      '#default_value' => !empty($this->settings['default_value']['default_value']) ? $this->settings['default_value']['default_value'] : '',
      '#maxlength' => 255,
    );
    $form['default_value']['use_tokens'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use Tokens in Default Value'),
      '#default_value' => !empty($this->settings['default_value']['use_tokens']),
    );
    $form['default_value']['contexts'] = array(
      '#title' => t('Substitutions'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['default_value']['contexts']['contexts'] = $this
      ->getCtoolsSubstitutionsList();
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function configureFormSubmit($form, &$form_state, $flexiform) {
    $this->settings['default_value']['default_value'] = $form_state['values']['default_value']['default_value'];
    $this->settings['default_value']['use_tokens'] = $form_state['values']['default_value']['use_tokens'];
    parent::configureFormSubmit($form, $form_state, $flexiform);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlexiformElement::$bundle protected property The bundle this is on.
FlexiformElement::$element_namespace protected property The namespace of this element.
FlexiformElement::$entity_namespace protected property The entity namespace of the entity this element is acting on.
FlexiformElement::$entity_type protected property The entity type this field is on.
FlexiformElement::$flexiform protected property The flexiform entity this element is one.
FlexiformElement::$settings protected property The settings for this element.
FlexiformElement::$weight protected property The weight of this element.
FlexiformElement::configureFormValidate public function Validate the configure form for the element. 3
FlexiformElement::createElement public static function Create an element object.
FlexiformElement::formIsEmpty public function Work out if the submitted value constitutes empty. 1
FlexiformElement::getCtoolsContexts public function Get an array of ctools context for the flexiform.
FlexiformElement::getCtoolsSubstitutionsList public function Build a list of possible ctools substitutions.
FlexiformElement::getElement public static function Get an element object.
FlexiformElement::getElementNamespace public function Get the element namespace for this form element.
FlexiformElement::getEntityNamespace public function Get the entity namespace for this form element.
FlexiformElement::getEntityType public function Get the entity type for this element.
FlexiformElement::getSettings public function Get the settings.
FlexiformElement::getWeight public function Get the weight of this form element.
FlexiformElement::label public function Get the label for this form element. 2
FlexiformElement::makeElementNamespace public function Make namespace for the element. 1
FlexiformElement::name public function Get the name for this form element.
FlexiformElement::removeForm public function Build the remove form for the element.
FlexiformElement::removeFormSubmit public function Submit the remove form for the element.
FlexiformElement::removeFormValidate public function Validate the remove form for the element.
FlexiformElement::replaceCtoolsSubstitutions public function Replace ctools substitutions with their values.
FlexiformElement::setLabel public function Set the label for this form element. 1
FlexiformElement::setWeight public function Set the weight of this form element. 1
FlexiformElement::toSettingsArray public function Convert this object into a settings array. 5
FlexiformElement::type public function Get the type of this form element. 3
FlexiformElement::__construct public function Construct the class. 3
PartyActivityElementTitle::configureForm public function Build the configure form for the element. Overrides FlexiformElement::configureForm
PartyActivityElementTitle::configureFormSubmit public function Submit the configure form for the element. Overrides FlexiformElement::configureFormSubmit
PartyActivityElementTitle::form public function Return the form element for this FlexiformElement. Overrides FlexiformElement::form
PartyActivityElementTitle::formExtractValues public function Extract the submitted values for this form element. Overrides FlexiformElement::formExtractValues
PartyActivityElementTitle::formSubmit public function Submit the form element. Overrides FlexiformElement::formSubmit
PartyActivityElementTitle::formValidate public function Validate the form element. Overrides FlexiformElement::formValidate