Code Monkey home page Code Monkey logo

field_tag's Introduction

Field context
=============

Field context module provides a way for developers to reference field instances
in abstract terms rather than actual field names, allowing you to write a
future-proof code in cases where exact field names need to be known.

You only need to enabled it if a module depends on it or if you want to
integrate it in your own development.

Installation
------------

Install it just like any other Drupal module - place it in the modules
directory for your site and enable it on the "admin/modules" page.

Usage
-----

Note: Although Field context does not have a hard dependency on Field UI
module, you have to enable Field UI (field_ui) module in order to be able to
set contexts for fields via user interface.

A field context can be set in the form that adds or edits field instances for
any bundle of any entity.

### Nodes

If you wish to add field contexts for node fields:
1. Go to Structure > Content types section of the site (admin/structure/types).
2. Click on "manage fields" link for the content type of your choice.
3. If you do not have defined fields, add a field and select a field context
in the "Field context" section of the field edit form.
4. If you want to add a field context for existing field, click on "edit" link
for selected field and select a field context in the "Field context" section of
the field edit form.

### Users

If you wish to add field contexts for user fields:
1. Go to Configuration > Account settings section of the site
(admin/config/people/accounts).
2. Click on "Manage fields" tab.
3. Select field contexts the same way you would do for node fields.

Predefined contexts
-------------------

For user convenience developers can predefine contexts using hooks so that
users can select field contexts using drop-down list with predefined context
options.

See fieldcontext.api.php file for examples and documentation.

Integration with Features
-------------------------

All field contexts associated with field instances are automatically included
in field instance settings when they are exported via Features.

Integration with Rules
----------------------

The module provides a Rules condition to determine whether an entity has a field
with a particular context and an action to fetch the field name with a specified
context.

Use case
--------

Your client wants to have a website that lists his paintings and drawings, with
all paintings and drawings with price over โ‚ฌ 1000 promoted to the front page
automatically. Your client also wants to be able to add different types of art
in the future himself and also have them promoted to the front page using the
same price threshold.

As a developer, you do the following:

1. Create two node content types: Painting and Drawing.
2. Add a field "Price" (field_painting_price) that is attached to Painting
content type, and assign "price" context to the field.
3. Add a field "Price" (field_drawing_price) that is attached to Drawing
content type, and assign "price" context to the field.
4. Create a hook that sets $node->promote to 1 upon node saving if the field
value with "price" context is greater that 1000.
5. Instruct your client that when he creates a Sculpture node content type and
adds a field "Price" (field_oh_thisis_f0r_price_right) to the Sculpture content
type himself in the future, he merely needs to select "Price" context for the
field in order to have expensive sculptures promoted to the front page.

Test cases
----------

The module contains a sub-module "Field context Test" that provides sample data
for Field context module test cases. It is required by test cases that are
included in fieldcontext.test file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.