Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Latest commit

 

History

History
95 lines (59 loc) · 4.06 KB

addingfields.md

File metadata and controls

95 lines (59 loc) · 4.06 KB

Adding Fields to DKAN

The following will allow you to add new fields to DKAN content types like Dataset.

The result will create a new field "MY NEW FIELD" as on the Dataset form:

dataset form

which will appear on the Dataset view when content is entered:

dataset view

Adding the New Field

Let's add a field to the Dataset content type as an example.

  • Go to /admin/structure/types/manage/dataset/fields in your browser:

field manage page

  • Scroll down till you see the Add new field input row

  • Let's add a MY NEW FIELD field as an example:

Add new field

  • Press Save and proceed with the field setup:

Adjust Where Field Appears on Form

  • Adjust weight of field to control where it appears on the form:

adjust weight

Adjust Where Field Appears on Dataset Page

  • Click "Manage Display" to adjust where it appears in the output

  • To add to the "Dataset Info" table on the Dataset view drag to "Dataset Information" group

  • Remember to hide the "Label" for display in the table:

Adjust label

We provide hook implementations in order to add extra options or remove existing ones to/from the field_license options

Adding/Removing License Options to/From License Field

In order to add options to the existing ones you need to implement hook_license_subscribe in the following fashion:

    // Let's asume we want to do this as part of the fictitious license_options_extra module
    function license_options_extra_subscribe() {
      return array(
        'tcl' => array(
          'label' => 'Talis Community License (TCL)',
          'uri' => 'http://opendefinition.org/licenses/tcl/',
        ),
      );
    }

The code above add the Talis Community License (TCL) license referencing it to the tcl key. It also provides a link to the license (optional). You can provide as many options as you want through the array being returned.

Removing License Options

In order to remove options from the existing ones you need to implement hook_license_unsubscribe in the following fashion:

    // Let's asume we want to do this as part of the fictitious license_options_extra module
    function license_options_extra_unsubscribe() {
      return array(
        'notspecified',
      );
    }

The code above removes the notspecified option. You can provide as many options as you want through the array being returned.

Additional notes about the behavior of both hooks

  • The options provided through the license drupal field configuration are COMPLETELY ignored.
  • hook_license_subscribe implementations are of course called before hook_license_unsubscribe implementations.
  • Options subscribed through hook_license_subscribe are processed as they come through the order of modules provided by the drupal registry.
  • If multiple options are provided using the same key then it grabs the first one that comes in and ignores the rest
  • If you want to replace and item that already exists, unsubscribe the existing key and provided an alternative one for your option

References to the code

  • Hooks are invoked here
  • Field formatter implementation for the license field is in here