<?php
require_once DRUPAL_ROOT . '/core/modules/field/tests/modules/field_test/field_test.entity.inc';
require_once DRUPAL_ROOT . '/core/modules/field/tests/modules/field_test/field_test.field.inc';
require_once DRUPAL_ROOT . '/core/modules/field/tests/modules/field_test/field_test.storage.inc';
function field_test_permission() {
$perms = array(
'access field_test content' => array(
'title' => t('Access field_test content'),
'description' => t('View published field_test content.'),
),
'view test_view_field content' => array(
'title' => t('View test field content'),
'description' => t('View published test_view_field content.'),
),
'administer field_test content' => array(
'title' => t('Administer field_test content'),
'description' => t('Manage field_test content'),
),
);
return $perms;
}
function field_test_menu() {
$items = array();
$bundles = field_info_bundles('test_entity');
foreach ($bundles as $bundle_name => $bundle_info) {
$items['test-entity/add/' . $bundle_name] = array(
'title' => t('Add %bundle test_entity', array(
'%bundle' => $bundle_info['label'],
)),
'page callback' => 'field_test_entity_add',
'page arguments' => array(
2,
),
'access arguments' => array(
'administer field_test content',
),
'type' => MENU_NORMAL_ITEM,
);
}
$items['test-entity/manage/%field_test_entity_test/edit'] = array(
'title' => 'Edit test entity',
'page callback' => 'field_test_entity_edit',
'page arguments' => array(
2,
),
'access arguments' => array(
'administer field_test content',
),
'type' => MENU_NORMAL_ITEM,
);
$items['test-entity/nested/%field_test_entity_test/%field_test_entity_test'] = array(
'title' => 'Nested entity form',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'field_test_entity_nested_form',
2,
3,
),
'access arguments' => array(
'administer field_test content',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function field_test_field_test_op($entity_type, $entity, $field, $instance, $langcode, &$items) {
return array(
$langcode => hash('sha256', serialize(array(
$entity_type,
$entity,
$field['field_name'],
$langcode,
$items,
))),
);
}
function field_test_field_test_op_multiple($entity_type, $entities, $field, $instances, $langcode, &$items) {
$result = array();
foreach ($entities as $id => $entity) {
$field_name = $instances[$id]['field_name'];
$result[$id] = array(
$langcode => hash('sha256', serialize(array(
$entity_type,
$entity,
$field_name,
$langcode,
$items[$id],
))),
);
}
return $result;
}
function field_test_field_available_languages_alter(&$langcodes, $context) {
if (state()
->get('field_test.field_available_languages_alter')) {
$langcodes[] = 'xx';
$index = array_search('en', $langcodes);
unset($langcodes[$index]);
}
}
function field_test_field_language_alter(&$display_langcode, $context) {
if (state()
->get('field_test.language_fallback') ?: TRUE) {
field_language_fallback($display_langcode, $context['entity'], $context['langcode']);
}
}
function field_test_memorize($key = NULL, $value = NULL) {
$memorize =& drupal_static(__FUNCTION__, NULL);
if (!isset($key)) {
$return = $memorize;
$memorize = array();
return $return;
}
if (is_array($memorize)) {
$memorize[$key][] = $value;
}
}
function field_test_field_create_field($field) {
$args = func_get_args();
field_test_memorize(__FUNCTION__, $args);
}
function field_test_entity_label_callback($entity_type, $entity, $langcode = NULL) {
return 'label callback ' . $entity->ftlabel;
}
function field_test_field_attach_view_alter(&$output, $context) {
if (!empty($context['display']['settings']['alter'])) {
$output['test_field'][] = array(
'#markup' => 'field_test_field_attach_view_alter',
);
}
}
function field_test_field_widget_properties_alter(&$widget, $context) {
if (in_array($context['entity_type'], array(
'node',
'comment',
)) && $context['field']['field_name'] == 'alter_test_text') {
$widget['settings']['size'] = 42;
}
}
function field_test_field_widget_properties_user_alter(&$widget, $context) {
if ($context['field']['field_name'] == 'alter_test_options') {
$widget['type'] = 'options_buttons';
}
}
function field_test_field_widget_form_alter(&$element, &$form_state, $context) {
switch ($context['field']['field_name']) {
case 'alter_test_text':
drupal_set_message('Field size: ' . $context['instance']
->getWidget()
->getSetting('size'));
break;
case 'alter_test_options':
drupal_set_message('Widget type: ' . $context['instance']
->getWidget()
->getPluginId());
break;
}
if ($context['default']) {
drupal_set_message('From hook_field_widget_form_alter(): Default form is true.');
}
}
function field_test_query_efq_table_prefixing_test_alter(&$query) {
$query
->join('test_entity', 'te2', '%alias.ftid = test_entity.ftid');
}
function field_test_query_efq_metadata_test_alter(&$query) {
global $efq_test_metadata;
$efq_test_metadata = $query
->getMetadata('foo');
}
function field_test_field_formatter_settings_form_alter(&$element, &$form_state, $context) {
$element['field_test_formatter_settings_form_alter'] = array(
'#type' => 'textfield',
'#title' => t('Formatter settings form alter'),
'#default_value' => $context['formatter']
->getSetting('field_test_formatter_settings_form_alter'),
);
}
function field_test_field_formatter_settings_summary_alter(&$summary, $context) {
$summary .= '<br />field_test_field_formatter_settings_summary_alter';
}
function field_test_field_extra_fields_alter(&$info) {
unset($info['node']['no_fields']);
}