123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <?php
- require_once DRUPAL_ROOT . '/modules/field/tests/field_test.entity.inc';
- require_once DRUPAL_ROOT . '/modules/field/tests/field_test.field.inc';
- require_once DRUPAL_ROOT . '/modules/field/tests/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.'),
- ),
- '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) {
- $bundle_url_str = str_replace('_', '-', $bundle_name);
- $items['test-entity/add/' . $bundle_url_str] = 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(&$languages, $context) {
- if (variable_get('field_test_field_available_languages_alter', FALSE)) {
-
- $languages[] = 'xx';
-
- $index = array_search('en', $languages);
- unset($languages[$index]);
- }
- }
- function field_test_field_language_alter(&$display_language, $context) {
- if (variable_get('field_test_language_fallback', TRUE)) {
- locale_field_language_fallback($display_language, $context['entity'], $context['language']);
- }
- }
- 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_query_alter(&$query) {
- if (!empty($query->alterMyExecuteCallbackPlease)) {
- $query->executeCallback = 'field_test_dummy_field_storage_query';
- }
- }
- function field_test_dummy_field_storage_query(EntityFieldQuery $query) {
-
- return array(
- 'user' => array(
- 1 => entity_create_stub_entity('user', array(1, NULL, NULL)),
- ),
- );
- }
- function field_test_entity_label_callback($entity) {
- 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');
- }
- if (isset($output['test_field'])) {
- $output['test_field'][] = array('#markup' => 'field language is ' . $context['language']);
- }
- }
- 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']['widget']['settings']['size']);
- break;
- case 'alter_test_options':
- drupal_set_message('Widget type: ' . $context['instance']['widget']['type']);
- break;
- }
- }
- function field_test_query_efq_table_prefixing_test_alter(&$query) {
-
-
- $query->join('test_entity','te2','%alias.ftid = test_entity.ftid');
- }
- function field_test_query_store_global_test_query_alter($query) {
-
-
-
-
- $GLOBALS['test_query'] = $query;
- }
|