class FlexiformFormEntityFieldCollection in Flexiform 7
Form entity to get a field collection item.
Hierarchy
- class \FlexiformFormEntityBase implements FlexiformFormEntityInterface
Expanded class hierarchy of FlexiformFormEntityFieldCollection
1 string reference to 'FlexiformFormEntityFieldCollection'
File
- includes/
form_entity/ field_collection.form_entity.inc, line 10 - Contains class for a basic entity getter.
View source
class FlexiformFormEntityFieldCollection extends FlexiformFormEntityBase {
/**
* {@inheritdoc}
*/
public function getEntity() {
parent::getEntity();
$settings = $this->settings;
$base_type = $this
->getParamType('base');
// Get the base entity.
$base_entity = $this
->getParam('base');
// Check we have enough information to load the entity.
if (!$base_entity) {
return FALSE;
}
if ($settings['delta'] == 'new') {
$field = field_info_field($settings['bundle']);
$item_count = count($base_entity->{$settings['bundle']}[LANGUAGE_NONE]);
if ($field['cardinality'] < 0 || $item_count < $field['cardinality']) {
$target_entity = entity_create('field_collection_item', array(
'field_name' => $settings['bundle'],
));
$target_entity
->setHostEntity($base_type, $base_entity);
}
}
else {
if (empty($base_entity->{$this->getter['field_name']}[LANGUAGE_NONE][$settings['delta']]['value'])) {
if ($settings['create']) {
$target_entity = entity_create('field_collection_item', array(
'field_name' => $settings['bundle'],
));
$target_entity
->setHostEntity($base_type, $base_entity);
}
}
else {
// Load the entity;
$target_id = $base_entity->{$this->getter['field_name']}[LANGUAGE_NONE][$settings['delta']]['value'];
$target_entity = entity_load_single('field_collection_item', $target_id);
}
}
if (!$target_entity) {
return FALSE;
}
// Check the entity is the right bundle.
list(, , $bundle) = entity_extract_ids('field_collection_item', $target_entity);
if ($bundle != $settings['bundle']) {
return FALSE;
}
return $target_entity;
}
/**
* {@inheritdoc}
*/
public function configForm($form, &$form_state) {
$form = parent::configForm($form, $form_state);
$field = field_info_field($this->settings['bundle']);
if ($field['cardinality'] != 1) {
$options = array();
$options['new'] = t('Always New Item');
$i = 0;
while ($i < 10) {
if ($field['cardinality'] > 0 && $i >= $field['cardinality']) {
break;
}
$options[$i] = $i + 1;
++$i;
}
$form['settings']['delta'] = array(
'#title' => t('Delta'),
'#type' => 'select',
'#description' => t('Select which value of this field you want to use. If "Always New Item" is selected, a new item will be added unless there is no space for one, in which case no entity will be provided.'),
'#options' => $options,
'#default_value' => !empty($this->settings['delta']) ? $this->settings['delta'] : 0,
);
}
$form['settings']['create'] = array(
'#title' => t('Create if Empty'),
'#description' => t('When ticked, if the field item is empty, a new collection will be created.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->settings['create']),
);
return $form;
}
}
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 |
Submit the Configuration Form. Overrides FlexiformFormEntityInterface:: |
|
FlexiformFormEntityBase:: |
public | function |
Validate the configuration form. Overrides FlexiformFormEntityInterface:: |
|
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. | |
FlexiformFormEntityFieldCollection:: |
public | function |
Get the Configuration Form. Overrides FlexiformFormEntityBase:: |
|
FlexiformFormEntityFieldCollection:: |
public | function |
Get the entity for the form. Overrides FlexiformFormEntityBase:: |