class FlexiformFormEntityBase in Flexiform 7
Default Form Entity Class for Managing a form Entity.
Hierarchy
- class \FlexiformFormEntityBase implements FlexiformFormEntityInterface
Expanded class hierarchy of FlexiformFormEntityBase
File
- includes/
form_entity/ base.form_entity.inc, line 10 - Contains class for a basic entity getter.
View source
class FlexiformFormEntityBase implements FlexiformFormEntityInterface {
/**
* The Flexiform Entity Manager
* @var FlexiformFormEntityManagerInterface
*/
public $manager;
/**
* The namespace of this entity.
* @var string
*/
public $entity_namespace;
/**
* The type of this entity.
* @var string
*/
public $entity_type;
/**
* Details of the getter.
* @var array
*/
public $getter = array();
/**
* The settings for this entity on the flexiform.
* @var array
*/
public $settings = array();
/**
* Construct a Flexiform Form Entity class.
*
* @param FlexiformFormEntityManagerInterface $manager
* @param string $namespace
* @param array $getter
* @param array $settings (Optional)
*/
public function __construct(FlexiformFormEntityManagerInterface $manager, $namespace, $getter, $settings = array()) {
$this->manager = $manager;
$this->entity_namespace = $namespace;
$this->getter = $getter;
$this->settings = $this->manager
->getEntitySettings($namespace) ?: $settings;
$this->entity_type = $this->settings['entity_type'];
}
/**
* Get a Parameter From the Entity Manager.
*
* @return
* An entity object.
*/
public function getParam($param_name) {
return $this->manager
->getEntity($this->settings['parameters'][$param_name]);
}
/**
* Get a Parameter's entity settings from the Entity Manager.
*/
public function getParamSettings($param_name) {
return $this->manager
->getEntitySettings($this->settings['parameters'][$param_name]);
}
/**
* Get the entity type of a parameter.
*/
public function getParamType($param_name) {
return $this->manager
->getEntityType($this->settings['parameters'][$param_name]);
}
/**
* Check bundle.
*
* @param $entity
* The entity to check.
*
* @return boolean
* True if the entity is the right bundle for this form entity. False
* otherwise.
*/
public function checkBundle($entity) {
list(, , $bundle) = entity_extract_ids($this->entity_type, $entity);
if ($bundle == $this->settings['bundle']) {
return TRUE;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getEntity() {
if (isset($this->settings['save_on_submit']) && empty($this->settings['save_on_submit'])) {
$this->manager
->skipOnSave($this->entity_namespace, TRUE);
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function saveEntity($entity) {
entity_save($this->entity_type, $entity);
}
/**
* {@inheritdoc}
*/
public function configForm($form, &$form_state) {
$form['settings'] = array(
'#type' => 'container',
'#tree' => TRUE,
);
$form['settings']['save_on_submit'] = array(
'#type' => 'checkbox',
'#title' => t('Save Entity on Submit'),
'#description' => t('Should this entity always be saved on submit?'),
'#default_value' => isset($this->settings['save_on_submit']) ? $this->settings['save_on_submit'] : TRUE,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Settings'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function configFormValidate($form, &$form_state) {
}
/**
* {@inheritdoc}
*/
public function configFormSubmit($form, &$form_state) {
$this->settings = $form_state['values']['settings'] + $this->settings;
$this->manager
->updateEntitySettings($this->entity_namespace, $this->settings);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlexiformFormEntityBase:: |
public | property | The namespace of this entity. | |
FlexiformFormEntityBase:: |
public | property | The type of this entity. | |
FlexiformFormEntityBase:: |
public | property | Details of the getter. | |
FlexiformFormEntityBase:: |
public | property | The Flexiform Entity Manager | |
FlexiformFormEntityBase:: |
public | property | The settings for this entity on the flexiform. | |
FlexiformFormEntityBase:: |
public | function | Check bundle. | |
FlexiformFormEntityBase:: |
public | function |
Get the Configuration Form. Overrides FlexiformFormEntityInterface:: |
3 |
FlexiformFormEntityBase:: |
public | function |
Submit the Configuration Form. Overrides FlexiformFormEntityInterface:: |
|
FlexiformFormEntityBase:: |
public | function |
Validate the configuration form. Overrides FlexiformFormEntityInterface:: |
|
FlexiformFormEntityBase:: |
public | function |
Get the entity for the form. Overrides FlexiformFormEntityInterface:: |
12 |
FlexiformFormEntityBase:: |
public | function | Get a Parameter From the Entity Manager. | |
FlexiformFormEntityBase:: |
public | function | Get a Parameter's entity settings from the Entity Manager. | |
FlexiformFormEntityBase:: |
public | function | Get the entity type of a parameter. | |
FlexiformFormEntityBase:: |
public | function |
Save the entity upon submission of the form. Overrides FlexiformFormEntityInterface:: |
5 |
FlexiformFormEntityBase:: |
public | function | Construct a Flexiform Form Entity class. |