You are here

class FlexiformElementFlexiform in Flexiform 7

Class to embed one flexiform inside another.

Hierarchy

Expanded class hierarchy of FlexiformElementFlexiform

2 string references to 'FlexiformElementFlexiform'
flexiform_flexiform_element_info in ./flexiform.flexiform.inc
Implements hook_flexiform_element_info().
hook_flexiform_element_info in ./flexiform.api.php
Define elements for use in flexiforms.

File

includes/element/flexiform.element.inc, line 10
Contains FlexiformElementFlexiform class.

View source
class FlexiformElementFlexiform extends FlexiformElement {

  /**
   * The form name of the form.
   */
  protected $form;

  /**
   * Overrides FlexiformElement::__construct().
   */
  public function __construct($flexiform, $settings, $element_namespace = '') {
    parent::__construct($flexiform, $settings, $element_namespace);
    $this->form = $this->element_info['form'];
    $this->label = $settings['label'];
    $this->weight = $settings['weight'];
  }

  /**
   * Overrires FlexiformElement::label().
   */
  public function label() {
    return $this->settings['label'];
  }

  /**
   * Return the type.
   */
  public function type() {
    return 'Flexiform';
  }

  /**
   * Get the flexiform object of the embedded form.
   */
  public function getFlexiform() {
    return flexiform_load($this->form);
  }

  /**
   * Build the configure form for the element.
   */
  public function configureForm($form, &$form_state, $flexiform) {
    $form = parent::configureForm($form, $form_state, $flexiform);
    $link = l(t('Edit @flexiform', array(
      '@flexiform' => $this
        ->label(),
    )), 'admin/structure/flexiform/manage/' . $this->form);
    $form['description'] = array(
      '#weight' => -1,
      '#markup' => t('There are no settings for @flexiform as it is a nested form. You can edit the flexiform by clicking on the link below, however these changes will effect the form everywhere it is used.<br />!link', array(
        '@flexiform' => $this
          ->label(),
        '!link' => $link,
      )),
    );
    return $form;
  }

  /**
   * Overrides FlexiformElement::form().
   */
  public function form($form, &$form_state, $entity) {
    $form = parent::form($form, $form_state, $entity);
    $sub_form = array(
      '#parents' => $form['#parents'] + array(
        $this->element_namespace,
      ),
    );
    $builder = $this
      ->getFlexiform()
      ->getBuilder($entity);
    $form[$this->element_namespace]['#flexiform_builder'] = $builder;
    $form[$this->element_namespace]['#flexiform_element'] = $this;
    $form[$this->element_namespace]['#flexiform'] = $this
      ->getFlexiform();
    $form[$this->element_namespace]['#type'] = 'fieldset';
    $form[$this->element_namespace]['#title'] = $this
      ->label();
    $form[$this->element_namespace] += $builder
      ->form($sub_form, $form_state, $entity);
    return $form;
  }

  /**
   * Overrides FlexiformElement::formValidate().
   */
  public function formValidate($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
    $sub_form = $form[$this->element_namespace];
    $sub_form['#flexiform_builder']
      ->formValidate($sub_form, $form_state);
  }

  /**
   * Overrides FlexiformElement::formSubmit().
   */
  public function formSubmit($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
    $sub_form = $form[$this->element_namespace];
    $sub_form['#flexiform_builder']
      ->formSubmit($sub_form, $form_state);
  }

  /**
   * Overrides FlexifromElement::toSettingsArray();
   */
  public function toSettingsArray() {
    $settings = parent::toSettingsArray();
    $settings['type'] = 'flexiform';
    $settings['form'] = $this->form;
    $settings['label'] = $this
      ->label();
    return $settings;
  }

}

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::configureFormSubmit public function Submit the configure form for the element. 10
FlexiformElement::configureFormValidate public function Validate the configure form for the element. 3
FlexiformElement::createElement public static function Create an element object.
FlexiformElement::formExtractValues public function Extract the submitted values for this form element. 12
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::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
FlexiformElementFlexiform::$form protected property The form name of the form.
FlexiformElementFlexiform::configureForm public function Build the configure form for the element. Overrides FlexiformElement::configureForm
FlexiformElementFlexiform::form public function Overrides FlexiformElement::form(). Overrides FlexiformElement::form
FlexiformElementFlexiform::formSubmit public function Overrides FlexiformElement::formSubmit(). Overrides FlexiformElement::formSubmit
FlexiformElementFlexiform::formValidate public function Overrides FlexiformElement::formValidate(). Overrides FlexiformElement::formValidate
FlexiformElementFlexiform::getFlexiform public function Get the flexiform object of the embedded form.
FlexiformElementFlexiform::label public function Overrires FlexiformElement::label(). Overrides FlexiformElement::label
FlexiformElementFlexiform::toSettingsArray public function Overrides FlexifromElement::toSettingsArray(); Overrides FlexiformElement::toSettingsArray
FlexiformElementFlexiform::type public function Return the type. Overrides FlexiformElement::type
FlexiformElementFlexiform::__construct public function Overrides FlexiformElement::__construct(). Overrides FlexiformElement::__construct