You are here

class FlexiformDisplayBase in Flexiform 7

Base class for all flexiform displays.

Hierarchy

Expanded class hierarchy of FlexiformDisplayBase

File

includes/flexiform.display.inc, line 80
Specify base display classes for flexiforms.

View source
class FlexiformDisplayBase implements FlexiformDisplayInterface {

  /**
   * The Flexiform the display is for.
   *
   * @var Flexiform
   */
  protected $flexiform;

  /**
   * {@inheritdoc}
   */
  public function getFlexiform() {
    return $this->flexiform;
  }
  public function __construct(Flexiform $flexiform, array $configuration = array()) {
    $this->flexiform = $flexiform;
    $this->configuration = $configuration;
  }

  /**
   * Get the base entity for a flexiform.
   *
   * By default we just create a new entity.
   */
  public function getBaseEntity($context = array()) {
    $info = entity_get_info($this->flexiform->base_entity);
    $values = array();
    if (!empty($info['entity keys']['bundle'])) {
      $values[$info['entity keys']['bundle']] = $this->flexiform->base_entity_bundle;
    }
    $base_entity = entity_create($this->flexiform->base_entity, $values);

    // Make sure the entity label is always set to play nicely with ctools.
    if (!empty($info['entity keys']['label']) && !isset($base_entity->{$info['entity keys']['label']})) {
      $base_entity->{$info['entity keys']['label']} = '';
    }

    // Make sure the id key is always set to play nicely with ctools.
    if (!empty($info['entity keys']['id']) && !isset($base_entity->{$info['entity keys']['id']})) {
      $base_entity->{$info['entity keys']['id']} = NULL;
    }
    return $base_entity;
  }

  /**
   * Is this display enabled.
   */
  public function isEnabled() {
    return !empty($this->configuration['enabled']);
  }

  /**
   * Build the form ready for rendering.
   */
  public function build($context = array()) {
    module_load_include('inc', 'flexiform', 'includes/flexiform.flexiform');
    $base_entity = $this
      ->getBaseEntity($context);
    module_invoke_all('flexiform_prepare_base_entity', $base_entity, $this->flexiform, $this);

    // Allow other modules to change the form wrapper.
    $wrapper = 'flexiform_wrapper';
    drupal_alter('flexiform_wrapper', $wrapper, $this, $context);
    $args = isset($context['args']) ? $context['args'] : array();
    array_unshift($args, $base_entity);
    array_unshift($args, $this->flexiform);
    return call_user_func_array($wrapper, $args);
  }

  /**
   * Get the title.
   */
  public function title($context = array()) {
    return $this->flexiform->label;
  }

  /**
   * Build the config form.
   */
  public function configForm($form, &$form_state) {
    $form['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => 'Enabled',
      '#default_value' => !empty($this->configuration['enabled']),
    );
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#default_value' => !empty($this->configuration['title']) ? $this->configuration['title'] : '',
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function getPath($base_entity_id = NULL) {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function access($context = array()) {
    $base_entity = $this
      ->getBaseEntity($context);
    return $this
      ->getFlexiform()
      ->getAccessController(get_class($this))
      ->checkAccess($base_entity);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlexiformDisplayBase::$flexiform protected property The Flexiform the display is for.
FlexiformDisplayBase::access public function Check the access for this form display. Overrides FlexiformDisplayInterface::access 1
FlexiformDisplayBase::build public function Build the form ready for rendering. Overrides FlexiformDisplayInterface::build 2
FlexiformDisplayBase::configForm public function Build the config form. Overrides FlexiformDisplayInterface::configForm 3
FlexiformDisplayBase::getBaseEntity public function Get the base entity for a flexiform. Overrides FlexiformDisplayInterface::getBaseEntity 4
FlexiformDisplayBase::getFlexiform public function Retrieve the flexiform for this display. Overrides FlexiformDisplayInterface::getFlexiform
FlexiformDisplayBase::getPath public function Get the path, if applicable, for the display. Overrides FlexiformDisplayInterface::getPath 1
FlexiformDisplayBase::isEnabled public function Is this display enabled. 1
FlexiformDisplayBase::title public function Get the title. Overrides FlexiformDisplayInterface::title 1
FlexiformDisplayBase::__construct public function