当前位置: 首页>>代码示例>>PHP>>正文


PHP field_info_instance函数代码示例

本文整理汇总了PHP中field_info_instance函数的典型用法代码示例。如果您正苦于以下问题:PHP field_info_instance函数的具体用法?PHP field_info_instance怎么用?PHP field_info_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了field_info_instance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: preprocess

 /**
  * {@inheritdoc}
  */
 public function preprocess($value)
 {
     // Text field. Check if field has an input format.
     $field_info = field_info_field($this->getProperty());
     // If there was no bundle that had the field instance, then return NULL.
     if (!($instance = field_info_instance($this->getEntityType(), $this->getProperty(), $this->getBundle()))) {
         return NULL;
     }
     $return = NULL;
     if ($field_info['cardinality'] == 1) {
         // Single value.
         if (!$instance['settings']['text_processing']) {
             return $value;
         }
         return array('value' => $value, 'format' => 'filtered_html');
     }
     // Multiple values.
     foreach ($value as $delta => $single_value) {
         if (!$instance['settings']['text_processing']) {
             $return[$delta] = $single_value;
         } else {
             $return[$delta] = array('value' => $single_value, 'format' => 'filtered_html');
         }
     }
     return $return;
 }
开发者ID:jhoffman-tm,项目名称:waldorf-deployment,代码行数:29,代码来源:ResourceFieldEntityText.php

示例2: hook_studyroom_time_increment_update

/**
 * Provides a method to update date fields that use a time increment value.
 *
 * @param int $time_increment
 *   The new time increment value.
 */
function hook_studyroom_time_increment_update($time_increment)
{
    foreach (studyroom_reservation_types() as $bundle) {
        $instance = field_info_instance('studyroom_reservation', 'field_reservation_datetime', $bundle->type);
        $instance['widget']['settings']['increment'] = $time_increment;
        field_update_instance($instance);
    }
}
开发者ID:EWB,项目名称:studyrooms,代码行数:14,代码来源:studyroom.api.php

示例3: bunsen_form_alter

function bunsen_form_alter(&$form, &$form_state, $form_id)
{
    $form_type = !empty($form['type']['#value']) ? $form['type']['#value'] : '';
    $form['#attributes']['class'][] = 'form-horizontal';
    // Add icons to action buttons
    $form['actions']['submit']['#value'] .= '&nbsp;&nbsp;<i class="fa fa-save"></i>';
    if (!empty($form['actions']['delete'])) {
        $form['actions']['delete']['#value'] .= '&nbsp;&nbsp;<i class="fa fa-ban"></i>';
    }
    // Remove node settings at the bottom of form
    unset($form['additional_settings']);
    foreach ($form as $key => $element) {
        if (is_array($form[$key]) && isset($form[$key]['#group'])) {
            unset($form[$key]);
        }
        // Wrap certain form element types with Bootstrap column classes
        if (strrpos($key, 'field_', -strlen($key)) !== FALSE || $key == 'title') {
            $field_info = field_info_instance('node', $key, $form_type);
            $field_type = !empty($field_info['widget']['type']) ? $field_info['widget']['type'] : '';
            $column_prefix = '<span class="col-md-8">';
            $column_suffix = '</span>';
            $adjust_col = FALSE;
            if ($key == 'title') {
                $form_elem =& $form[$key];
                $adjust_col = TRUE;
            } else {
                switch ($field_type) {
                    case "text_textarea":
                        break;
                    case "file_generic":
                        $form_elem =& $form[$key][LANGUAGE_NONE][0];
                        $adjust_col = TRUE;
                        break;
                    case "number":
                        $form_elem =& $form[$key][LANGUAGE_NONE][0]['value'];
                        $column_prefix = '<span class="col-md-2 input-type-number">';
                        $adjust_col = TRUE;
                        break;
                    case "text_textfield":
                        $form_elem =& $form[$key][LANGUAGE_NONE][0]['value'];
                        $adjust_col = TRUE;
                        break;
                    default:
                        $form_elem =& $form[$key][LANGUAGE_NONE];
                        $adjust_col = TRUE;
                        break;
                }
            }
            if ($adjust_col) {
                $prefix = !empty($form_elem['#field_prefix']) ? $form_elem['#field_prefix'] : '';
                $suffix = !empty($form_elem['#field_suffix']) ? $form_elem['#field_suffix'] : '';
                $form_elem['#field_prefix'] = $column_prefix . $prefix;
                $form_elem['#field_suffix'] = $suffix . $column_suffix;
            }
        }
    }
}
开发者ID:signaltrace-dev,项目名称:d7-theme-bunsen,代码行数:57,代码来源:template.php

示例4: publicFieldsInfo

 /**
  * Overrides \RestfulEntityBaseNode::publicFieldsInfo().
  */
 public function publicFieldsInfo()
 {
     $public_fields = parent::publicFieldsInfo();
     unset($public_fields['self']);
     $public_fields['created'] = array('property' => 'created');
     $public_fields['updated'] = array('property' => 'changed');
     if (field_info_instance($this->getEntityType(), OG_AUDIENCE_FIELD, $this->getBundle())) {
         $public_fields['company'] = array('property' => OG_AUDIENCE_FIELD, 'resource' => array('company' => array('name' => 'companies', 'full_view' => FALSE)));
     }
     return $public_fields;
 }
开发者ID:Gizra,项目名称:hedley-server,代码行数:14,代码来源:HedleyEntityBaseNode.php

示例5: publicFieldsInfo

 public function publicFieldsInfo()
 {
     $public_fields = parent::publicFieldsInfo();
     if ($this->getBundle()) {
         $public_fields['vsite'] = array('property' => OG_AUDIENCE_FIELD, 'process_callbacks' => array(array($this, 'vsiteFieldDisplay')));
     }
     $public_fields['body'] = array('property' => 'body', 'sub_property' => 'value');
     if (field_info_instance($this->getEntityType(), 'field_upload', $this->getBundle())) {
         $public_fields['files'] = array('property' => 'field_upload', 'process_callbacks' => array(array($this, 'fileFieldDisplay')));
     }
     return $public_fields;
 }
开发者ID:aleph-n,项目名称:opencholar,代码行数:12,代码来源:OsNodeRestfulBase.php

示例6: dateForm

 /**
  * @todo.
  */
 public function dateForm($field_name, $field_type, $widget_type, $todate = TRUE)
 {
     // Tests that date field functions properly.
     $edit = array();
     $edit['title'] = $this->randomName(8);
     if ($widget_type == 'date_select') {
         $edit[$field_name . '[und][0][value][year]'] = '2010';
         $edit[$field_name . '[und][0][value][month]'] = '10';
         $edit[$field_name . '[und][0][value][day]'] = '7';
         $edit[$field_name . '[und][0][value][hour]'] = '10';
         $edit[$field_name . '[und][0][value][minute]'] = '30';
         if ($todate) {
             $edit[$field_name . '[und][0][show_todate]'] = '1';
             $edit[$field_name . '[und][0][value2][year]'] = '2010';
             $edit[$field_name . '[und][0][value2][month]'] = '10';
             $edit[$field_name . '[und][0][value2][day]'] = '7';
             $edit[$field_name . '[und][0][value2][hour]'] = '11';
             $edit[$field_name . '[und][0][value2][minute]'] = '30';
         }
     } elseif ($widget_type == 'date_popup') {
         $edit[$field_name . '[und][0][value][date]'] = '10/07/2010';
         $edit[$field_name . '[und][0][value][time]'] = '10:30';
         if ($todate) {
             $edit[$field_name . '[und][0][show_todate]'] = '1';
             $edit[$field_name . '[und][0][value2][date]'] = '10/07/2010';
             $edit[$field_name . '[und][0][value2][time]'] = '11:30';
         }
     }
     // Test that the date is displayed correctly using both the 'short' and
     // 'long' date types.
     //
     // For the short type, save an explicit format and assert that is the one
     // which is displayed.
     variable_set('date_format_short', 'l, m/d/Y - H:i:s');
     $instance = field_info_instance('node', $field_name, 'story');
     $instance['display']['default']['settings']['format_type'] = 'short';
     field_update_instance($instance);
     $this->drupalPost('node/add/story', $edit, t('Save'));
     $this->assertText($edit['title'], "Node has been created");
     $should_be = $todate ? 'Thursday, 10/07/2010 - 10:30 to 11:30' : 'Thursday, 10/07/2010 - 10:30';
     $this->assertText($should_be, "Found the correct date for a {$field_type} field using the {$widget_type} widget displayed using the short date format.");
     // For the long format, do not save anything, and assert that the displayed
     // date uses the expected default value of this format provided by Drupal
     // core ('l, F j, Y - H:i').
     $instance = field_info_instance('node', $field_name, 'story');
     $instance['display']['default']['settings']['format_type'] = 'long';
     field_update_instance($instance);
     $this->drupalPost('node/add/story', $edit, t('Save'));
     $this->assertText($edit['title'], "Node has been created");
     $should_be = $todate ? 'Thursday, October 7, 2010 - 10:30 to 11:30' : 'Thursday, October 7, 2010 - 10:30';
     $this->assertText($should_be, "Found the correct date for a {$field_type} field using the {$widget_type} widget displayed using the long date format.");
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:55,代码来源:DateFieldTest.php

示例7: hook_goals_completed_goal

/**
 * Notification to modules that a goal is completed.
 *
 * @param int $goal_id
 *   Goal being completed.
 * @param int $uid
 *   UserID of user completing the goal.
 */
function hook_goals_completed_goal($goal_id, $uid)
{
    if (field_info_instance('goal', 'goal_userpoints', 'goal_bundle') && function_exists('userpoints_userpointsapi')) {
        $goals = entity_load('goal', array($goal_id));
        $goal = $goals[$goal_id];
        $point_array = field_get_items('goal', $goal, 'goal_userpoints');
        $points = $point_array[0]['value'];
        if ($points) {
            $params = array('uid' => $uid, 'points' => $points, 'description' => t('Goal @goal completed.', array('@goal' => $goal->title)));
            userpoints_userpointsapi($params);
        }
    }
}
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:21,代码来源:goals.api.php

示例8: sand_theme_preprocess_node

/**
 * Implements template_preprocess_node, replacing selected static 
 * field values with form elements that allow them to be edited.
 */
function sand_theme_preprocess_node(&$variables)
{
    // Only applies to specific node type 'request'
    if ($variables['type'] == 'request') {
        //We don't need to show comments or links with this form
        if (isset($variables['content']['comments'])) {
            unset($variables['content']['comments']);
        }
        if (isset($variables['content']['links'])) {
            unset($variables['content']['links']);
        }
        // Call the form builder function for 'request_updater'
        // with current node->nid as an extra parameter
        $status_form = drupal_get_form('request_updater', $variables['nid']);
        $weight_max = -999;
        // Check whether there is a returned form that can be displayed
        if ($status_form['#access']) {
            foreach ($status_form['fields_replaced']['#value'] as $field) {
                // For each field in the form with a corresponding static field that has
                // been populated, copy the weight of the static field to the form
                // element and delete the static element.
                if (isset($variables['content'][$field])) {
                    $status_form[$field]['#weight'] = $variables['content'][$field]['#weight'];
                    $weight_max = max($weight_max, $status_form[$field]['#weight']);
                    unset($variables['content'][$field]);
                } else {
                    $inst = field_info_instance('node', $field, 'request');
                    $status_form[$field]['#weight'] = $inst['display']['default']['weight'];
                    $weight_max = max($weight_max, $status_form[$field]['#weight']);
                }
            }
            // Node fields that have been populated and not matched to a form element just stay
            // as they are
            foreach ($variables['content'] as $field => $status) {
                if (isset($variables['content'][$field]['#weight'])) {
                    $weight_max = max($weight_max, $variables['content'][$field]['#weight']);
                }
            }
            // Merge the elements of the form with the remaining content elements into
            // the content array.
            $variables['content'] = array_merge($status_form, $variables['content']);
            // $weight_max should now equal to the largest weight of any content element
            // so add 1 to make sure that the 'Save' button appears at the bottom
            $variables['content']['submit_button']['#weight'] = $weight_max + 1;
        } else {
            // If there's no form to be displayed, no change is made to the content array
            // and we still have the regular static display for the node
        }
    }
}
开发者ID:Akenward,项目名称:sand_theme,代码行数:54,代码来源:template.php

示例9: field_load

 /**
  * Load a field's configuration and instance configuration by an
  * entity_type.bundle.field_name identifier.
  */
 protected function field_load($identifier)
 {
     list($entity_type, $field_name, $bundle) = explode('.', $identifier);
     $field_info = field_info_field($field_name);
     $instance_info = field_info_instance($entity_type, $field_name, $bundle);
     if ($field_info && $instance_info) {
         unset($field_info['id']);
         unset($field_info['bundles']);
         unset($instance_info['id']);
         unset($instance_info['field_id']);
         return array('field_config' => $field_info, 'field_instance' => $instance_info);
     }
     return FALSE;
 }
开发者ID:gnulugtn,项目名称:portal,代码行数:18,代码来源:FieldConfiguration.php

示例10: testFieldInstanceCreation

 /**
  * Test instance field creation.
  *
  * @dataProvider fieldDataProvider
  */
 public function testFieldInstanceCreation($field_name, $type, $label, $widget, $default_formatter, $teaser_formatter)
 {
     $base_handler = new DefaultBaseFieldHandler($field_name, $type);
     $base_handler->save();
     $handler = new DefaultInstanceFieldHandler($field_name, 'node', self::CONTENT_TYPE_WITHOUT_FIELDS);
     $handler->label($label)->widget($widget)->display('default', $default_formatter, 'inline')->display('teaser', $teaser_formatter);
     $instance = $handler->getField();
     $handler->save();
     $saved_instance = field_info_instance('node', $field_name, self::CONTENT_TYPE_WITHOUT_FIELDS);
     $this->assertEquals($label, $saved_instance['label']);
     $this->assertEquals($widget, $saved_instance['widget']['type']);
     $this->assertEquals($default_formatter, $saved_instance['display']['default']['type']);
     $this->assertEquals($teaser_formatter, $saved_instance['display']['teaser']['type']);
     field_delete_field($field_name);
 }
开发者ID:janoka,项目名称:platform-dev,代码行数:20,代码来源:DefaultFieldHandlerTest.php

示例11: __construct

 /**
  * Constructor for the Add to cart form. Provide $nid as the id of the
  * product display node. Other optional arguments are product reference field
  * name, view mode of the product display node and language of the product
  * display node. If optional arguments are not provided, their default values
  * are assumed, which are "field_product", "default" and "en" respectively.
  *
  * @param int $nid
  *   Product display node id.
  */
 public function __construct($nid)
 {
     $args = func_get_args();
     array_shift($args);
     $field_name = array_shift($args);
     $view_mode = array_shift($args);
     $language = array_shift($args);
     if (is_null($field_name)) {
         $field_name = 'field_product';
     }
     if (is_null($view_mode)) {
         $view_mode = 'default';
     }
     if (is_null($language)) {
         $language = 'en';
     }
     $node = node_load($nid);
     $instance = field_info_instance('node', $field_name, $node->type);
     $display = field_get_display($instance, $view_mode, $node);
     $settings = array_merge(field_info_formatter_settings($display['type']), $display['settings']);
     $field_product = field_get_items('node', $node, $field_name);
     $product_id = $field_product[0]['product_id'];
     $products = commerce_product_load_multiple(array($product_id));
     $type = !empty($settings['line_item_type']) ? $settings['line_item_type'] : 'product';
     $line_item = commerce_product_line_item_new(commerce_product_reference_default_product($products), $settings['default_quantity'], 0, array(), $type);
     $line_item->data['context']['product_ids'] = array_keys($products);
     $line_item->data['context']['add_to_cart_combine'] = !empty($settings['combine']);
     $line_item->data['context']['show_single_product_attributes'] = !empty($settings['show_single_product_attributes']);
     $cart_context = array('entity_type' => 'node', 'entity_id' => $nid, 'display' => 'default', 'language' => $language);
     $cart_context['class_prefix'] = $cart_context['entity_type'] . '-' . $nid;
     $cart_context['view_mode'] = $cart_context['entity_type'] . '_' . $view_mode;
     $entity_uri = entity_uri($cart_context['entity_type'], $node);
     $arguments = array('form_id' => commerce_cart_add_to_cart_form_id(array($product_id)), 'line_item' => $line_item, 'show_quantity' => $settings['show_quantity']);
     // Add the display path and referencing entity data to the line item.
     if (!empty($entity_uri['path'])) {
         $arguments['line_item']->data['context']['display_path'] = $entity_uri['path'];
     }
     $arguments['line_item']->data['context']['entity'] = array('entity_type' => $cart_context['entity_type'], 'entity_id' => $cart_context['entity_id'], 'product_reference_field_name' => $field_name);
     // Update the product_ids variable to point to the entity data if we're
     // referencing multiple products.
     if (count($arguments['line_item']->data['context']['product_ids']) > 1) {
         $arguments['line_item']->data['context']['product_ids'] = 'entity';
     }
     parent::__construct($arguments['form_id'], $arguments['line_item'], $arguments['show_quantity'], $cart_context);
     $this->cart_context = $cart_context;
     $this->arguments = $arguments;
 }
开发者ID:redcrackle,项目名称:redtest-core,代码行数:57,代码来源:CommerceAddToCartForm.php

示例12: describe

 /**
  * {@inheritdoc}
  */
 function describe($api, $entity_type, $keys)
 {
     if (!empty($this->bundlesByType[$entity_type])) {
         if ('user' === $entity_type) {
             $instance = field_info_instance('user', $this->fieldKey, 'user');
             foreach ($keys as $key => $title) {
                 $api->addRule($key, $title);
             }
             $api->descWithLabel($instance['label'], t('Field'));
         }
         foreach ($this->bundlesByType[$entity_type] as $bundle_name) {
             if (isset($keys[$bundle_name])) {
                 $instance = field_info_instance($entity_type, $this->fieldKey, $bundle_name);
                 $api->addRule($bundle_name, $keys[$bundle_name]);
                 $api->descWithLabel($instance['label'], t('Field'), $bundle_name);
             }
         }
         // $api->addDescription('(' . $this->fieldKey . ')');
     }
 }
开发者ID:radicalsuz,项目名称:fe,代码行数:23,代码来源:Abstract.php

示例13: getSourceStubEntity

 /**
  * Given a relationship, gets the stub entity for the source.
  *
  * @param array $relationship The relationship array.
  *
  * @return bool|mixed Either the stub entity or false on error.
  */
 protected function getSourceStubEntity(array $relationship)
 {
     $field_name = $relationship['field_name'];
     $source_entity_ids = entity_get_id_by_uuid($relationship['source_type'], array($relationship['source_uuid']));
     $source_entity_id = count($source_entity_ids) > 0 ? reset($source_entity_ids) : null;
     $source_entity_vids = entity_get_id_by_uuid($relationship['source_type'], array($relationship['source_vuuid']), true);
     $source_entity_vid = count($source_entity_vids) > 0 ? reset($source_entity_vids) : false;
     if (!$source_entity_id) {
         return false;
     }
     // Get the bundle for the source entity.
     $source_entity_bundle = Entity::getBundleFromID($relationship['source_type'], $source_entity_id);
     if (!$source_entity_bundle) {
         return false;
     }
     // Get the stub entity for the source.
     $source_stub = Entity::getStub($relationship['source_type'], $source_entity_id, $source_entity_bundle, $source_entity_vid);
     // Load the existing field onto the entity.
     $field_instance_info = field_info_instance($relationship['source_type'], $field_name, $source_entity_bundle);
     if ($field_instance_info === false) {
         return false;
     }
     try {
         // First, load the revisions.
         field_attach_load_revision($relationship['source_type'], array($source_entity_id => $source_stub), array('field_id' => $field_instance_info['field_id']));
         // Second, get the original deltas for the revision.
         $deltas = db_select('field_revision_' . $field_name, 'fr')->fields('fr', array('language', 'delta'))->condition($source_entity_vid ? 'revision_id' : 'entity_id', $source_entity_vid ? $source_entity_vid : $source_entity_id)->condition('language', field_available_languages($relationship['source_type'], $field_instance_info), 'IN')->orderBy('delta')->execute();
         // Assign the deltas to their languages.
         $deltas_languages = array();
         foreach ($deltas as $delta) {
             if (!array_key_exists($delta->language, $deltas_languages)) {
                 $deltas_languages[$delta->language] = array();
             }
             $deltas_languages[$delta->language][] = $delta->delta;
         }
         // Reset the deltas to their correct orders.
         $field_value =& $source_stub->{$field_name};
         foreach ($deltas_languages as $language => $deltas) {
             $new_value = array();
             for ($i = 0; $i < count($field_value[$language]); $i++) {
                 $new_value[$deltas[$i]] = $field_value[$language][$i];
             }
             $field_value[$language] = $new_value;
         }
     } catch (\Exception $ex) {
         // If an exception was thrown, that probably means the field doesn't
         // exist, so we should return false.
         return false;
     }
     return $source_stub;
 }
开发者ID:sammarks,项目名称:publisher,代码行数:58,代码来源:RelationshipHandler.php

示例14: deleteInstanceField

 /**
  * Delete field instance given label, base field name, entity type and bundle.
  *
  * @param string $field_name
  *    Machine name of an existing base field.
  * @param string $entity_type
  *    Entity type machine name.
  * @param string $bundle
  *    Bundle machine name.
  */
 public function deleteInstanceField($field_name, $entity_type, $bundle)
 {
     if ($instance = field_info_instance($entity_type, $field_name, $bundle)) {
         field_delete_instance($instance);
     }
 }
开发者ID:ec-europa,项目名称:platform-dev,代码行数:16,代码来源:Config.php

示例15: getFieldInstance

 /**
  * Returns field instance from field name for the given entity.
  *
  * @param string $field_name
  *   Field name.
  *
  * @return mixed $instance
  *   An instance array if one exists, FALSE otherwise.
  *
  * @throws \EntityMalformedException
  */
 public function getFieldInstance($field_name)
 {
     list(, , $bundle) = entity_extract_ids($this->entity_type, $this->entity);
     return field_info_instance($this->entity_type, $field_name, $bundle);
 }
开发者ID:vishalred,项目名称:redtest-core-pw,代码行数:16,代码来源:Entity.php


注:本文中的field_info_instance函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。