Tripal
Functions
tripal_core.chado_nodes.title_and_path.inc File Reference

Functions

 chado_get_node_title ($node)
 
 chado_add_admin_form_set_title (&$form, &$form_state, $details)
 
 chado_add_admin_form_set_title_form_validate ($form, $form_state)
 
 chado_add_admin_form_set_title_form_submit ($form, $form_state)
 
 chado_node_get_title_format ($content_type, &$tokens, $base_table=NULL)
 
 chado_node_get_legacy_title_default ($content_type)
 
 chado_get_node_url ($node)
 
 chado_set_node_url ($node)
 
 chado_update_existing_node_urls ($content_type, $job_id=0)
 
 chado_add_admin_form_set_url (&$form, &$form_state, $details)
 
 chado_add_admin_form_set_url_form_validate ($form, $form_state)
 
 chado_add_admin_form_set_url_form_submit ($form, $form_state)
 
 chado_node_get_url_format ($content_type, &$tokens, $base_table=NULL)
 
 chado_node_get_legacy_url_default ($content_type)
 
 chado_node_add_token_format ($application, $content_type, $format, $tokens)
 
 chado_node_get_token_format ($application, $content_type, $options=[])
 
 chado_node_get_unique_constraint_format ($base_table, $format_type='title')
 
 chado_node_generate_tokens ($base_table, $token_prefix=FALSE, $location_prefix=FALSE)
 
 chado_get_token_value ($token_info, $node, $options=[])
 
 chado_node_format_tokens ($tokens)
 
 chado_sort_tokens_by_location ($tokenA, $tokenB)
 
 tripal_sort_key_length_asc ($a, $b)
 
 chado_node_get_readable_format ($token)
 
 chado_node_get_location_from_token ($token)
 

Detailed Description

Contains API functions to set titles and paths for all chado nodes

TITLES

There are three steps to implement the ability to set custom titles for the node type: 1) Add the 'chado_node_api' elements to the hook_node_info function(). These values define the name of the base table and how to refer to nodes in singular and plural. There are additional paramaters that can be added to the 'chado_node_api' for syncing nodes (see documentation for the chado_node_sync_form() function for additional options.

function modulename_node_info() {
return array(
'chado_example' => array(
'name' => t('example'),
'base' => 'chado_example',
'description' => t('A Chado example is a collection of material that can be
sampled and have experiments performed on it.'),
'has_title' => TRUE,
'locked' => TRUE,
// this is what differs from the regular Drupal-documented hook_node_info()
'chado_node_api' => array(
'base_table' => 'example', // the name of the chado base table
'hook_prefix' => 'chado_example', // usually the name of the node type
'record_type_title' => array(
'singular' => t('Example'), // Singular human-readable title
'plural' => t('Examples') // Plural human-readable title
),
)
),
);
}

2) Add the "Set Page Titles" Form to the admin settings form

// If the module is using the "Chado Node: Title & Path API" to allow custom
titles
// for your node type then you need to add the configuration form for this
functionality.
$details = array(
'module' => 'tripal_example', // the name of the MODULE implementing
the content type
'content_type' => 'chado_example', // the name of the content type
// An array of options to use under "Page Titles"
// the key should be the token and the value should be the human-readable
option
'options' => array(
'[example.name]' => 'Germplasm Name Only',
'[example.uniquename]' => 'Germplasm Unique Name Only',
// there should always be one options matching the unique constraint.
// If you have a more human-readable constraint, then that is preferrable.
// See the tripal feature module for a good example of this.
'[example.example_id]' => 'Unique Contraint: The Chado ID for Examples'
),
// the token indicating the unique constraint in the options array
'unique_option' => '[example.example_id]'
);
// This call adds the configuration form to your current form
// This sub-form handles it's own validation & submit
chado_add_admin_form_set_title($form, $form_state, $details);
chado_add_admin_form_set_title(&$form, &$form_state, $details)
Definition: tripal_core.chado_nodes.title_and_path.inc:265

3) Use chado_get_node_title($node) where ever you want the title for your node. This should be done in hook_load(), hook_node_insert(), hook_node_update(). The reason you set the title in the node_action hooks, which act on all nodes, is because at that point you have the generic loaded node.

function tripal_example_load($nodes) {
foreach ($nodes as $nid => $node) {
// Add all of the custom content for your node type.
// See tripal_example.chado_node.api: chado_example_load()
// Now get the title
$node->title = chado_get_node_title($node);
$nodes[$nid] = $node;
}
}
chado_get_node_title($node)
Definition: tripal_core.chado_nodes.title_and_path.inc:213

Optionally define a default for a specific content type by implementing a function of the name [content type]_chado_node_default_title_format() that returns a string describing the default format.

function chado_example_chado_node_default_title_format() {
return '[example.example_id]';
}

If you don't implement this then a default format based on the unique constraint for the base table of the content type will be generated.

NODE URL/PATHS

There are three steps to implement the ability to set custom URLs for the node type: 1) Add the 'chado_node_api' elements to the hook_node_info function(). These values define the name of the base table and how to refer to nodes in singular and plural. There are additional paramaters that can be added to the 'chado_node_api' for syncing nodes (see documentation for the chado_node_sync_form() function for additional options.

function modulename_node_info() {
return array(
'chado_example' => array(
'name' => t('example'),
'base' => 'chado_example',
'description' => t('A Chado example is a collection of material that can be
sampled and have experiments performed on it.'),
'has_title' => TRUE,
'locked' => TRUE,
// this is what differs from the regular Drupal-documented hook_node_info()
'chado_node_api' => array(
'base_table' => 'example', // the name of the chado base table
'hook_prefix' => 'chado_example', // usually the name of the node type
'record_type_title' => array(
'singular' => t('Example'), // Singular human-readable title
'plural' => t('Examples') // Plural human-readable title
),
)
),
);
}

2) Add the "Set Page URLs" Form to the admin settings form

// If the module is using the "Chado Node: Title & Path API" to allow custom
URLs
// for your node type then you need to add the configuration form for this
functionality.
$details = array(
'module' => 'tripal_example', // the name of the MODULE implementing
the content type
'content_type' => 'chado_example', // the name of the content type
// An array of options to use under "Page URLs"
// the key should be the token and the value should be the human-readable
option
'options' => array(
'/example/[example.type_id>cvterm.name]/[example.example_id]' => 'Examples
separated by Type',
// there should always be one options matching the unique constraint.
// If you have a more human-readable constraint, then that is preferrable.
// See the tripal feature module for a good example of this.
'/example/[example.example_id]' => 'Unique Contraint: The Chado ID for
Examples'
),
);
// This call adds the configuration form to your current form
// This sub-form handles it's own validation & submit
chado_add_admin_form_set_url($form, $form_state, $details);
chado_add_admin_form_set_url(&$form, &$form_state, $details)
Definition: tripal_core.chado_nodes.title_and_path.inc:803

3) Use chado_set_node_url($node) where ever you want to reset the URL of the node. This should be done in hook_node_insert(), hook_node_update(). The reason you set the title in the node_action hooks, which act on all nodes, is because at that point you have the generic loaded node.

function tripal_example_node_insert($node) {
// Set the URL path after inserting.
switch ($node->type) {
case 'chado_example':
// Now use the API to set the path.
break;
}
}
chado_set_node_url($node)
Definition: tripal_core.chado_nodes.title_and_path.inc:615

Optionally define a default for a specific content type by implementing a function of the name [content type]_chado_node_default_url_format() that returns a string describing the default format.

function chado_example_chado_node_default_url_format() {
return '/example/[example.example_id]';
}

If you don't implement this then a default format based on the unique constraint for the base table of the content type will be generated.

Function Documentation

◆ chado_add_admin_form_set_title_form_submit()

chado_add_admin_form_set_title_form_submit (   $form,
  $form_state 
)

Implements hook_form_submit(). SUBMIT: Actually add the format specified by chado_add_admin_form_set_title()

◆ chado_add_admin_form_set_title_form_validate()

chado_add_admin_form_set_title_form_validate (   $form,
  $form_state 
)

Implements hook_form_validate(). VALIDATE: validate the format.

◆ chado_add_admin_form_set_url_form_submit()

chado_add_admin_form_set_url_form_submit (   $form,
  $form_state 
)

Implements hook_form_submit(). SUBMIT: Actually add the format specified by chado_add_admin_form_set_title()

◆ chado_add_admin_form_set_url_form_validate()

chado_add_admin_form_set_url_form_validate (   $form,
  $form_state 
)

Implements hook_form_validate(). VALIDATE: validate the format.

◆ chado_node_format_tokens()

chado_node_format_tokens (   $tokens)

Format a set of tokens for consistent display

Parameters
$tokensAn array of tokens from chado_node_generate_tokens()
Returns
HTML displaying the token list

◆ chado_node_get_location_from_token()

chado_node_get_location_from_token (   $token)

Returns the "location" as specified in the token information based on the token.

◆ chado_node_get_readable_format()

chado_node_get_readable_format (   $token)

Generate a Readable but not necessarily unique format based on a given primary key token.

For example, given the token [feature.type_id>cvterm.cvterm_id] you don't want the actual id indexed but instead would want the term name, [feature.type_id>cvterm.name]

◆ chado_sort_tokens_by_location()

chado_sort_tokens_by_location (   $tokenA,
  $tokenB 
)

This sorts tokens first by depth (ie: stock.* is before stock.*>subtable.*) and then alphabetically within a level (ie: stock.name comes before stock.type_id)

This is a usort callback and shouldn't be called directly. To use: usort($tokens, 'chado_sort_tokens_by_location');

◆ tripal_sort_key_length_asc()

tripal_sort_key_length_asc (   $a,
  $b 
)

Sorts an associative array by key length where sorter keys will be first

This is a uksort callback and shouldn't be called directly. To use; uksort($arr, 'tripal_sort_key_length_asc');