function flexiform_flexiform_element_info in Flexiform 7
Implements hook_flexiform_element_info().
File
- ./
flexiform.flexiform.inc, line 338 - All the flexiform hooks.
Code
function flexiform_flexiform_element_info() {
$elements = array();
// Get the element for all nested flexiforms.
$forms = db_select('flexiform', 'f')
->fields('f', array(
'label',
'form',
'base_entity',
'base_entity_bundle',
))
->execute()
->fetchAllAssoc('form');
foreach ($forms as $form) {
$elements[$form->base_entity][$form->base_entity_bundle]['flexiform:' . $form->form] = array(
'label' => $form->label,
'class' => 'FlexiformElementFlexiform',
'type' => 'form',
'group' => 'Flexiform',
'form' => $form->form,
);
}
// Get all entity properties
foreach (entity_get_property_info() as $entity_type => $info) {
$entity_properties = empty($info['properties']) ? array() : $info['properties'];
if (isset($info['bundles'])) {
foreach ($info['bundles'] as $bundle => $binfo) {
$properties = empty($binfo['properties']) ? array() : $binfo['properties'];
$properties += $entity_properties;
foreach ($properties as $name => $property) {
// If it is a field api field. Use the field api logic later.
if (!empty($property['field'])) {
continue;
}
else {
if (!empty($property['setter callback'])) {
$class = 'FlexiformElementEntityProperty';
if (!empty($property['type'])) {
$type = $property['type'];
if ($list = entity_property_list_extract_type($type)) {
$type = $list;
}
$class = 'FlexiformElementEntityProperty_' . $type;
}
$elements[$entity_type][$bundle]['property:' . $name] = array(
'label' => $property['label'],
'class' => class_exists($class) ? $class : 'FlexiformElementEntityProperty',
'type' => 'property',
'group' => 'Property',
'property' => $name,
);
}
}
}
// Add field_api_fields.
foreach (field_info_instances($entity_type, $bundle) as $field_name => $instance) {
$field = field_info_field($field_name);
$field_class = 'FlexiformElementField_' . $field['type'];
$elements[$entity_type][$bundle]['field:' . $field_name] = array(
'label' => $instance['label'],
'class' => class_exists($field_class) ? $field_class : 'FlexiformElementField',
'type' => 'field',
'group' => 'Field',
'field_name' => $field_name,
);
}
}
}
else {
foreach ($entity_properties as $name => $property) {
if (!empty($property['setter callback'])) {
$class = 'FlexiformElementEntityProperty';
if (!empty($property['type'])) {
$class = 'FlexiformElementEntityProperty_' . $property['type'];
}
$elements[$entity_type][$entity_type]['property:' . $name] = array(
'label' => $property['label'],
'class' => class_exists($class) ? $class : 'FlexiformElementEntityProperty',
'type' => 'property',
'group' => 'Property',
'property' => $name,
);
}
}
}
}
// Get all the field elements.
/*$fields_info = field_info_instances();
foreach ($fields_info as $entity_type => $entity_fields) {
foreach ($entity_fields as $bundle => $bundle_fields) {
foreach ($bundle_fields as $field_name => $instance) {
$field = field_info_field($instance['field_name']);
$field_class = 'FlexiformElementField_' . $field['type'];
$elements[$entity_type][$bundle]['field:' . $field_name] = array(
'label' => $instance['label'],
'class' => class_exists($field_class) ? $field_class : 'FlexiformElementField',
'type' => 'field',
'group' => 'Field',
'field_name' => $field_name,
);
}
}
}*/
// Get node elements
foreach (node_type_get_types() as $bundle => $info) {
if ($info->has_title) {
$elements['node'][$bundle]['node:title'] = array(
'label' => $info->title_label,
'class' => 'FlexiformElementNodeTitle',
'type' => 'title',
'group' => 'Node',
);
}
$elements['node'][$bundle]['node:author'] = array(
'label' => t('Authored by'),
'class' => 'FlexiformElementNodeAuthor',
'type' => 'author',
'group' => 'Node',
);
$elements['node'][$bundle]['node:status'] = array(
'label' => t('Published'),
'class' => 'FlexiformElementNodeStatus',
'type' => 'status',
'group' => 'Node',
);
$elements['node'][$bundle]['node:promote'] = array(
'label' => t('Promoted to front page'),
'class' => 'FlexiformElementNodePromote',
'type' => 'promote',
'group' => 'Node',
);
$elements['node'][$bundle]['node:sticky'] = array(
'label' => t('Sticky at top of lists'),
'class' => 'FlexiformElementNodeSticky',
'type' => 'sticky',
'group' => 'Node',
);
}
$elements['user']['user']['user:name'] = array(
'label' => t('Name'),
'class' => 'FlexiformElementUserName',
'type' => 'name',
'group' => 'User',
);
$elements['user']['user']['user:pass'] = array(
'label' => t('Password'),
'class' => 'FlexiformElementUserPass',
'type' => 'pass',
'group' => 'User',
);
$elements['user']['user']['user:mail'] = array(
'label' => t('E-mail'),
'class' => 'FlexiformElementUserMail',
'type' => 'mail',
'group' => 'User',
);
$elements['user']['user']['user:roles'] = array(
'label' => t('Roles'),
'class' => 'FlexiformElementUserRoles',
'type' => 'roles',
'group' => 'User',
);
// Include ctools content stuff.
$panes = $entity_panes = array();
if (module_exists('ctools')) {
ctools_include('content');
// Trying to make all ctools content types available is to expensive to fit
// into a reasonable load time so limit the exposed content types. Extra
// types can be exposed by changing the value of this variable.
$exposed_types = variable_get('flexiform_exposed_ctools_content', array(
'views_panes',
'entity_view',
));
foreach ($exposed_types as $name) {
$type = ctools_get_content_type($name);
$sub_types = ctools_content_get_subtypes($type);
if (empty($sub_types)) {
continue;
}
foreach ($sub_types as $sub => $info) {
if (!empty($info['required context']) && (!is_array($info['required context']) || count($info['required context']) === 1)) {
$context = $info['required context'];
if (is_array($context)) {
$context = reset($context);
}
if (!$context) {
continue;
}
$entity_type = $context->keywords;
if (substr($entity_type, 0, 7) == 'entity:') {
$entity_type = substr($entity_type, 7);
}
$entity_panes[$entity_type]["{$name}:{$sub}"] = array(
'type' => $name,
'subtype' => $sub,
'title' => $info['title'],
'category' => is_array($info['category']) ? reset($info['category']) : $info['category'],
);
}
}
}
}
// Add custom form elements to every entity type.
foreach (entity_get_info() as $entity_type => $info) {
foreach ($info['bundles'] as $bundle => $info) {
$elements[$entity_type][$bundle]['custom:html'] = array(
'label' => t('Custom HTML'),
'class' => 'FlexiformElementCustomHtml',
'type' => 'custom_html',
'group' => 'Custom',
);
if (!empty($entity_panes[$entity_type])) {
foreach ($entity_panes[$entity_type] as $name => $pinfo) {
$elements[$entity_type][$bundle]['ctools:' . $name] = array(
'label' => $pinfo['title'],
'class' => 'FlexiformElementCtoolsContent',
'type' => 'ctools_content',
'group' => $pinfo['category'],
'content_type' => $pinfo['type'],
'sub_type' => $pinfo['subtype'],
);
}
}
}
}
return $elements;
}