Use this tag for questions about the field API, how to use it, or which hooks are required to implement a field in a module; use "tag:fields" for questions about fields implemented in modules you are using.

learn more… | top users | synonyms

0
votes
1answer
31 views

Field Template Suggestions: Target a particular field type on a content type

I want to use a field template for all the fields on my "journal_page" content type that use a widget of "long text". How would I do this? N.B. My field is not named "long text". "Long text" is ...
0
votes
1answer
14 views

Custom field “required” validation

I built a custom field type using the Field API. In hook_field_validate I have some logic to validate some very custom stuff, but when I tried to add a "This field is required" validation, I realized ...
0
votes
1answer
17 views

Hide Price by Role for a Content Type in Drupal 7

I am trying to achieve the following: 1> Hide Price Field for a Role only on a specific content type. I am using Drupal Commerce. Things I tried: 1> Field Permissions for the commerce_price field on ...
0
votes
0answers
13 views

Unable to get a new field type created using the code below

I am trying to create a custom 'field type' using the code given below But still when I check in the manage fields section and check for field type dropdown I can see the field type "Custom Animcan ...
1
vote
0answers
20 views

How do I initially show 3 blank fields on a form when cardinality is unlimited?

I have created a field programmatically that has 'cardinality' => FIELD_CARDINALITY_UNLIMITED. This is the functionality that I want. I want users to be able to add as many items as they need to. ...
0
votes
0answers
5 views

Why does this field_update_instance() call not preserve all settings?

I'm working with Commerce + Addressfield (and Commerce Addressbook). In a hook_update_N I want to configure sensible defaults for the site, but one of them (default_country) refuses to stick. Why is ...
0
votes
0answers
42 views

Don't upload file on save

On Drupal 7, if a user doesn't click upload, the file is uploaded on save, but this can be a problem for large files and execution time limit. How can I disable this? I need the file being uploaded ...
0
votes
1answer
6 views

Additional field data stored outside of the field storage (in a separate table) doesn't load with the rest of the field

I've implemented a custom field that needs to store data outside of the Field Storage mechanism and in a custom DB table. (The field structure is enough to require a second table, but not enough to ...
1
vote
1answer
31 views

Saving values of a multistep form into custom entity fields

I'm building a module that implement a multistep form based on a custom entity. The entity contains fields which are created by the install file. I was able to create the steps and if I print the ...
1
vote
1answer
17 views

Enable field formatter settings

I have a field that I created using hook_field_extra_fields, and I want it to have a cogwheel like in the image below, so that I can customize it. Right now the only format setting for the field is ...
0
votes
1answer
20 views

how to alter a hook_field_insert

I am trying to find a way of altering the output of a hook_field_insert. In my exact example, I'm trying to hook into the link_field_insert hook, in the Link module: /** * Implements ...
0
votes
1answer
16 views

Check if entity reference field (user) contains current user

I have a node page of Project content type which contains a multiselect enitity reference field of user type called field_team. I also have a block created by my custom module which is displayed at ...
0
votes
1answer
29 views

Add custom text field to field settings form

In the admin when click edit on Manage Fields page it shows settings for that field. Can we add a custom property (checkbox) here like the required checkbox? For example, for a decimal field it show ...
0
votes
0answers
34 views

How do I programmatically copy an existing Field to another Entity?

I want to add two new fields to the Commerce Discount entity --- an image and a long text. And I want these to be visible through Views. I was going to use this code to add the fields: ...
0
votes
0answers
19 views

How to render views field without executing a view?

My task is to update field content via AJAX on node page and on view page both. On node page I can get rendered content of any field by calling field_view_field('node', $node, $field_name, ...
0
votes
1answer
40 views

how to get a field name by field label in Drupal 7

I have added a custom field with title 'play time'. How can I get the field name(internal value) using label value in my custom module. Is there any function to get the value?
1
vote
0answers
39 views

“Remove All” button for unlimited fields in Drupal 7

I've written a custom module for this functionality where my below code is able to delete the files but I think there should be a better way for doing that! <?php /** * Implements ...
0
votes
1answer
25 views

Allowed strings for the text field

I have the form which is created through Webform module and now I need to add one more text field but its value has to be unique and can be only the value from some predefined list of allowed values. ...
0
votes
0answers
18 views

add fields to a node mapped to date input.The fields value should be mapped to date value

I want to add fields to the a content type. The user should be able input text values that are mapped to a particular date. Ex: for july 1, a particular field can have a value of 145, for july 13 ...
0
votes
0answers
7 views

Read field value as string on login

In a custom module of mine (7.x), I succesfully call allocation_user_login(&$edit, $account) when the user logs in. The next step for me is to read the string value from the field field_group ...
0
votes
0answers
13 views

Losing custom #theme settings set in hook_field_widget_form after an error

I have defined a custom field in a custom module. The new field applies a custom font to the options, and I have run into an issue with the widget form after an error. I have implemented ...
0
votes
1answer
27 views

Base field provided by a module is not accessable

this is a follow up to my question here. In my .module file I use the following code to add a base field to all my nodes: /** * Implements hook_form_BASE_FORM_ID_alter() for node_form(). */ ...
0
votes
0answers
20 views

How do I properly define the widget for a file field attached to an entity type? [duplicate]

I'm creating a custom entity type and trying to add a file field to it. Amongst other field definitions I have the following in baseFieldDefinitions(): $fields['file'] = ...
0
votes
1answer
11 views

How to create a new entity that is fieldable

I am currently learning how to create entities in Drupal 7. I have successfully defined a new entity and made it fieldable. My question is how do a create a new instance of that entity? I understand ...
0
votes
1answer
62 views

Add field to existing content entity

I am trying to add a hidden field to all nodes in my module (for any node type even new ones being created later on). Would this be the correct code? $field_storage = ...
0
votes
1answer
11 views

Filter after Custom Field Type in Custom Filter

I'm facing a problem with a custom field type in a custom filter. The field type isn't showing up in my filter-criterias in views. Do I have to tell the fieldtype somehow that it is filterable? Or is ...
0
votes
1answer
35 views

Create themable field group

I have a custom entity with several fields. Now I would like to group the fields and give each group it's own twig template so that I would be able to compose a page (my custom entity) containing ...
0
votes
3answers
100 views

How to problematically display an image field in Drupal 7 + default value when needed

I've used field_view_field to display an image field for a specific entity in Drupal. The problem is when that entity doesn't have any value for field. I expect field_view_field to display the default ...
0
votes
0answers
78 views

Re use link field (of link module) in custom module to save custom data with it

Here goes background of my issue & question related to it: I am calling link_field_info() & changing some properties of field to use it with custom name. Code - function custom_field_info() ...
0
votes
1answer
69 views

Delete field and related data (field_delete_field, field_delete_instance)

I want to delete field from my Content Type using hook_update and wondering how to do it in most correct way. I know that my field is only on 1 Content Type (page). Here is my current solution. ...
0
votes
0answers
23 views

How to check the selected hour(eg:9am, 10am, 11 am,12pm in dropdown list) is between a range of hours using views exposed form

How to check the user input hour(eg:9am, 10am, 11 am,12pm in dropdown list) is between a range of hours(eg: office hours 9am - 6 am) in views exposed form. I am using BEF settings and installed the ...
0
votes
0answers
36 views

Field API and the database saving value from dynamic select

I have a custom module with custom field. I have two values to store in the database. The first one is a simple text field and it's working great. The second one is more complex. It's a radio ...
0
votes
0answers
53 views

How to build render array for image with custom link without using field_view_value()

In a custom module i implemented code to display a image which links to a custom destination. I got it working by building a render array with field_view_value(): Code snippet I: $link = ...
0
votes
0answers
7 views

How to integrate hook_field_extra_fields with hook_field_formatter_info (if possible)

I would like to know if it's possible to integrate a custom field defined with hook_field_extra_fields with a custom field formatter to be able to configure it by the UI custom settings on the ...
0
votes
0answers
32 views

My module's custom fields are not picked up by entity_metadata_wrapper and thus Rules

The problem I have is that I am using a module called Trackfield that defined a CCK field for D6, I (inexpertly) ported the module to D7 to use the Field API. My port works great and I have been using ...
1
vote
1answer
30 views

Replacing a certain character pattern in a textfield when saving an entity

I got an entity type containing a long text field. If a user types in a certain character pattern ("xX" for example), this string "xX" should replaced with "×" (the proper symbol for multiplication) ...
3
votes
1answer
37 views

Image field - 'Number of values' is not showing up in admin form

Something's very wierd with my existing Drupal 7 setup (current Drupal version, set up in early 2013, custom Zen Subtheme). When I create a new Content Type with a new Field Type "Image" this 'Number ...
0
votes
0answers
61 views

How to create a multifield programmatically without using features

I have a custom module that I am working on that uses a couple of custom content types. I am trying to keep the module as self-contained as possible and thus far I've been able to create my content ...
0
votes
1answer
22 views

Use Plugin Field inside buildForm()

In Drupal 8, I use this code inside my buildForm() method: $form['medias']['file'] = array( '#title' => t('Image'), '#type' => 'managed_file', '#upload_location' => ...
5
votes
2answers
230 views

Where should I be storing custom node-related data?

There are several types of data my website generates for every node. Node's popularity score, node's comment count obtained from a 3rd party API, etc... This data is set for every node. In the past ...
0
votes
0answers
14 views

How to find elements inside a commerce order form with dpm()? [duplicate]

I want to identify a specific field inside a commerce order form. The machine name of the field inside the order form is: commerce_customer_profile. Using Devel Themer I've got: ...
1
vote
1answer
29 views

When hook_field_info_alter is invoked?

I am trying drush cc all, but no luck. https://api.drupal.org/api/drupal/modules!field!field.api.php/function/hook_field_info_alter/7 I need to programmatically hide a field and thinks that this is ...
0
votes
2answers
51 views

Make form to show multiple field widgets with predefined values

I have a node form with multivalue field (cardinality unlimited). I need to show user 3 widgets if this field with predefined value (like shown at screenshot). At screenshots I show the current form, ...
0
votes
0answers
77 views

Prepopulate field collection programmatically

I have a content type with field collection field (unlimited cardinality). Each collection has image field (required) and long text field. How can I prepopulate node form with multiple collections? I ...
0
votes
3answers
72 views

create a taxonomy and attach a field to it programatically

how can i attach a field to an entity (vocabulary) programatically in drupal 8 I created a vocabulary $vocab = entity_create('taxonomy_vocabulary', array( 'name' => 'vocab_name', ...
0
votes
1answer
32 views

How to create a custom field with a custom FAPI element?

I am writing a custom field module for phone numbers. The field has 4 different parts: A select element to choose the type of phone number, (phone, fax, toll free, other), A text field for the ...
1
vote
1answer
61 views

Do I need a custom content type, entity, module or field?

I'm working on a product information manager, and I have a content type of product which needs to reference stock and price levels for each supplier from a different database - these are stored as ...
0
votes
0answers
20 views

How to create a field in tests in Drupal 8

I am writing a test in drupal 8, in this test(simpletest) i create a content type(using drupalCreateContentType). I need in this content type create some fields. Now i need a taxonomy field, but will ...
0
votes
0answers
13 views

Setting database keys / index on fields

How do I specify that a field should have an index? I can only see references to indexes in the search api, but that seems to be something completely different. How would I also create compound ...
0
votes
2answers
85 views

Removing required attribute on user entity fields not working

I have added fields to user entity and make them required and show on registration page. So the user signing up have to fill all the fields. On the admin side these all fields are coming but i don't ...