fields

D7 to D8 upgrade: fields, widgets and formatters

For fields, their widgets and their formatters, most of the hook-functions in D7 are replaced in D8 by classes with annotations.

At the time of writing, hooks still required to create the basics of a field are:

  • hook_field_schema() implementation in the /modules/modulename.install file
  • hook_field_info() and hook_field_is_empty() implementations in the /modules/modulename.module file

All the widget and formatter hooks have been retired. Here's what you'll have to add to re-instate the functionality provided by your widget and formatter hook implementations.
In the /modules directory you need to create the following files, each holding a class and its magic annotations.

  • modulename/lib/Drupal/modulename/Type/ModuleNameItem.php
  • modulename/lib/Drupal/modulename/Plugin/field/widget/ModuleNameDefaultWidget.php
  • modulename/lib/Drupal/modulename/Plugin/field/formatter/ModuleNameDefaultFormatter.php
Read more

Panopoly Apps Data Model

Content Types, Users, and Other Entities

In all probability, your app will add a few new fields to existing data models or create some new entities.

Create a Namespace

All machine names should be namespaced with the title of your app. For example, all Panopoly News fields, content types and views have "panopoly_news" applied to them.

Audiofield

Go back to AudioField

Installation

In order to activate this module you have to get one of audio players from the following links
1. http://wpaudioplayer.com/download *Note make sure you should download the standalone edition
2. http://sourceforge.net/projects/musicplayer/files/musicplayer/slim-playe...
3. http://www.premiumbeat.com/flash_music_players/original/single/
4. http://www.premiumbeat.com/flash_music_players/original/thin/
5. http://www.premiumbeat.com/flash_music_players/original/mini/
(Premiumbeat.com no longer offers the music players)
6. Install FlowPlayer module (http://drupal.org/project/flowplayer) to use Flowplayer (optional)
7.http://www.jplayer.org/ VERSION 2.0, not 2.1 (7.x-1.x only)
8. Soundmanager2 http://www.schillmania.com/projects/soundmanager2/doc/download/
9. Use Google reader player, no installation required. NEW

Where to extract the players?

Once you got any of the above audio players you have to create a new folder called "player "at this
directory "sites/all/libraries". Now you can unzip the audio players directly into the "player" folder.
If you wish to save players in different folder you can change it from admin/settings/audiofield and enter new path under "Audio Players Directory".

Read more

Modify attributes of a form field (EXAMPLE: ADD SIZE attribute of a multi select box to make it bigger)

Goal:

ADD(or or modify) an attribute of a form field.
For this example, we'll be ADDING the "size" attribute to a multi select box in a custom content type, with the intent to make the select box bigger, vertically, so that more options are visible at once.

What you'll need to know:

  1. How to create and enable a custom module (not covered here)
  2. my_form_id (The form ID of the form you want to change, see previous page for details)
  3. my_field_name (The field name of the form field you want to modify, see section below for details)
  4. my_content_type (The content type you're changing the fields for. Don't worry if you're not dealing with a content type form, the below info applies to just about any form you'll likely come across).

The resulting code:

<?php
/**
* Implements hook_form_alter().
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
  if(
$form_id == 'my_form_id'){
   
$form['my_field_name'][ $form['my_field_name']['#language'] ]['#size'] = '20';
  }
}
?>

The What, Where, and Why:

  if($form_id == 'my_form_id')
This IF statement is important if you you do not want to process every form on your site with this modification.

Read more

Fields classes

Remove classes from cck/core fields

fields.png

Remove label

Language support for entity fields

About multilingual fields

Entity fields natively implement multilingual support. The language associated with a field depends on a number of factors including if translation is enabled and the chosen translation method (e.g. for node entities, either node translation or field translation).

Before looking at the specific field language support, it is important to know the different possible entity configurations. For node entities, content types can be configured as follows:

  • Locale module is disabled
    • No language assignment
    • No translation
  • Locale module enabled
    • Language assignment
    • No translation
  • Locale and Content translation modules enabled
    • Language assignment
    • Translation via node translation method (multiple nodes)
  • Locale and Entity translation modules enabled
    • Language assignment
    • Translation via field translation method (one node)
Read more
Subscribe with RSS Syndicate content