You are here

class FlexiformFormEntityLoad in Flexiform 7

Form Entity that loads an entity from an id stored in config.

Hierarchy

Expanded class hierarchy of FlexiformFormEntityLoad

1 string reference to 'FlexiformFormEntityLoad'
flexiform_flexiform_entity_getter_info in ./flexiform.flexiform.inc
Implements hook_flexiform_entity_getter_info().

File

includes/form_entity/load.form_entity.inc, line 10
Contains class for a basic entity getter.

View source
class FlexiformFormEntityLoad extends FlexiformFormEntityBase {

  /**
   * {@inheritdoc}
   */
  public function getEntity() {
    parent::getEntity();
    $id = $this->settings['entity_id'];

    // Don't do anything if the $id is empty.
    if (empty($id)) {
      return FALSE;
    }

    // Handle path arguments.
    if (stripos($id, '%') === 0 && is_numeric(ltrim($id, '%'))) {

      // Try to use the standard drupal menu handling. This allows the use
      // of paths with load wildcards in them.
      $position = ltrim($id, '%');
      $menu_object = menu_get_object($this->entity_type, $position);
      if ($menu_object && $this
        ->checkBundle($menu_object)) {
        return $menu_object;
      }
      else {
        if ($menu_object) {
          return FALSE;
        }
      }

      // If the menu system hasn't yielded a result use the arg function.
      $id = arg($position);
    }
    $entity = entity_load_single($this->entity_type, $id);
    return $this
      ->checkBundle($entity) ? $entity : FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function configForm($form, &$form_state) {
    $form = parent::configForm($form, $form_state);
    $form['settings']['entity_id'] = array(
      '#type' => 'textfield',
      '#title' => t('Entity ID'),
      '#description' => t('You may also specify a position in the path to take the id from, e.g. "%2" will use the third section of the page path.'),
      '#default_value' => !empty($this->settings['entity_id']) ? $this->settings['entity_id'] : '',
      '#required' => TRUE,
    );
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlexiformFormEntityBase::$entity_namespace public property The namespace of this entity.
FlexiformFormEntityBase::$entity_type public property The type of this entity.
FlexiformFormEntityBase::$getter public property Details of the getter.
FlexiformFormEntityBase::$manager public property The Flexiform Entity Manager
FlexiformFormEntityBase::$settings public property The settings for this entity on the flexiform.
FlexiformFormEntityBase::checkBundle public function Check bundle.
FlexiformFormEntityBase::configFormSubmit public function Submit the Configuration Form. Overrides FlexiformFormEntityInterface::configFormSubmit
FlexiformFormEntityBase::configFormValidate public function Validate the configuration form. Overrides FlexiformFormEntityInterface::configFormValidate
FlexiformFormEntityBase::getParam public function Get a Parameter From the Entity Manager.
FlexiformFormEntityBase::getParamSettings public function Get a Parameter's entity settings from the Entity Manager.
FlexiformFormEntityBase::getParamType public function Get the entity type of a parameter.
FlexiformFormEntityBase::saveEntity public function Save the entity upon submission of the form. Overrides FlexiformFormEntityInterface::saveEntity 5
FlexiformFormEntityBase::__construct public function Construct a Flexiform Form Entity class.
FlexiformFormEntityLoad::configForm public function Get the Configuration Form. Overrides FlexiformFormEntityBase::configForm
FlexiformFormEntityLoad::getEntity public function Get the entity for the form. Overrides FlexiformFormEntityBase::getEntity