flexiform.display.inc in Flexiform 7
Specify base display classes for flexiforms.
File
includes/flexiform.display.inc
View source
<?php
interface FlexiformDisplayInterface {
public function getBaseEntity($context = array());
public function build($context = array());
public function title($context = array());
public function configForm($form, &$form_state);
public function getFlexiform();
public function getPath($base_entity_id = NULL);
public function access($context = array());
}
class FlexiformDisplayBase implements FlexiformDisplayInterface {
protected $flexiform;
public function getFlexiform() {
return $this->flexiform;
}
public function __construct(Flexiform $flexiform, array $configuration = array()) {
$this->flexiform = $flexiform;
$this->configuration = $configuration;
}
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);
if (!empty($info['entity keys']['label']) && !isset($base_entity->{$info['entity keys']['label']})) {
$base_entity->{$info['entity keys']['label']} = '';
}
if (!empty($info['entity keys']['id']) && !isset($base_entity->{$info['entity keys']['id']})) {
$base_entity->{$info['entity keys']['id']} = NULL;
}
return $base_entity;
}
public function isEnabled() {
return !empty($this->configuration['enabled']);
}
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);
$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);
}
public function title($context = array()) {
return $this->flexiform->label;
}
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;
}
public function getPath($base_entity_id = NULL) {
return NULL;
}
public function access($context = array()) {
$base_entity = $this
->getBaseEntity($context);
return $this
->getFlexiform()
->getAccessController(get_class($this))
->checkAccess($base_entity);
}
}