function _aet_insert_field_pre_render in Advanced Entity Tokens 7
The internal function of aet_insert_field_pre_render().
1 call to _aet_insert_field_pre_render()
- aet_insert_field_pre_render in aet_insert/
aet_insert.module - The pre-render callback for the AET Insert field.
File
- aet_insert/
aet_insert.fields.inc, line 11 - This file contains all the functions required for the creation of the AET Insert field.
Code
function _aet_insert_field_pre_render($element) {
// Adds another item to the data array which adds the next step in the
// filtering process.
$element['#data'][] = null;
// Add filters according to the received data.
foreach ($element['#data'] as $key => $data) {
$filter = aet_insert_get_filter($element, $key);
// Only add the filter if it has more than one option (NULL).
if (count($filter['#options']) > 1) {
$element['#children'][] = $filter;
}
}
// After adding all the filters check if the data had more than two entries
// and if so than also add the insert button.
if (count($element['#data']) > 2) {
$element['#children'][] = array(
'#type' => 'button',
'#value' => 'insert',
'#id' => $element['#id'] . '-insert-button',
'#attributes' => array(
'class' => array(
'aet-insert-button',
),
),
);
}
$element['#attributes']['class'] = isset($element['#attributes']['class']) ? $element['#attributes']['class'] : array();
$element['#attributes']['class'][] = 'aet_insert_field';
$element['#attributes']['class'][] = 'clearfix';
// Moves all the entity information to local variables for readability.
$entity_type = $element['#entity_type'];
$entity_id_key = $element['#entity_key'];
$entity_id = $element["#{$entity_id_key}"];
$bundle = $element['#bundle'];
$entity_uuid = AET_INSERT_UUID ? $element['#entity_uuid'] : FALSE;
// The below attributes will be passed to the HTML and will be used again when
// requesting the filter with different options.
$element['#attributes']['data-target'] = $element['#target'];
$element['#attributes']['data-entity-type'] = $entity_type;
$element['#attributes']['data-entity-key'] = $entity_id_key;
$element['#attributes']['data-entity-id'] = $entity_id;
$element['#attributes']['data-bundle'] = $bundle;
if ($entity_uuid) {
$element['#attributes']['data-entity-uuid'] = $entity_uuid;
}
return $element;
}