You are here

function fasttoggle_node_fasttoggle_available_links in Fasttoggle 7

Same name in this branch
  1. 7 fasttoggle.api.php \fasttoggle_node_fasttoggle_available_links()
  2. 7 module/fasttoggle_node/fasttoggle_node.module \fasttoggle_node_fasttoggle_available_links()

Get the list of potential links for an object type.

Parameters

string $type: (optional) The object type for which available links are being sought.

Return value

mixed If the parameter is NULL, returns an array containing all available links, indexed by type, is returned. If $type if not NULL, only the subtree for that type is returned. In the later case, hooks not supporting the chosen type may skip the work of doing any calculations or calls, saving time and memory.

File

./fasttoggle.api.php, line 21
Hooks provided by the Fasttoggle module.

Code

function fasttoggle_node_fasttoggle_available_links($type = NULL, $obj = NULL) {

  // This function only handles nodes so there's no point in doing anything if
  // we're not after nodes.
  if (!is_null($type) && $type != 'node') {
    return array();
  }

  // This is the structure that controls everything fasttoggle does.
  $result = array(
    'node' => array(
      // A brief name for the object type being matched.
      'id_field' => 'nid',
      // The name of the ID field for this object type.
      'title_field' => 'title',
      // Used in the non-ajax form.
      'save_fn' => 'fasttoggle_node_save',
      // (Optional) The non-generic function used for saving state changes.
      'object_type' => 'node',
      // The machine name for the object type. Used in menu paths, so should
      // not include spaces or other HTML special characters.
      'subtype_field' => 'type',
      // (Optional) The field in an object specifying the subtype.
      'access' => array(
        'fasttoggle_node_edit_access',
      ),
      // Optional an object-type wide access function (see below).
      'global_settings_desc' => t('In addition to these global settings, you need to enable fasttoogle in the settings page for each content type you wish to use.'),
      // The description to be used in the system wide settings page.
      'extra_settings' => array(
        // Extra values to be used in building the settings page.
        'help_text' => array(
          '#value' => t('Configure access restrictions for these settings on the <a href="@url">access control</a> page.', array(
            '@url' => url('admin/user/permissions', array(
              'fragment' => 'module-fasttoggle',
            )),
          )),
          '#prefix' => '<div>',
          '#suffix' => '</div>',
        ),
        'fasttoggle_enhance_node_overview_page' => array(
          // Extra elements may be added for submodule specific settings pages.
          '#type' => 'checkbox',
          '#title' => t('Add published/unpublished toggle links to the node overview page.'),
          '#default_value' => variable_get('fasttoggle_enhance_node_overview_page', TRUE),
          '#weight' => 50,
        ),
      ),
      'fields' => array(
        // 'fields' contains all the option information.
        'status' => array(
          // The toplevel in the array is the name of a group of options (eg
          // roles).
          'display' => array(
            'node_links',
          ),
          // A submodule may add additional items for its own purposes.
          'instances' => array(
            // The array of attributes of an object that may be toggled.
            'status' => array(
              // The name of the object (= published in this case).
              'description' => t('Status <small>(published/unpublished)</small>'),
              'default' => TRUE,
              // Whether enabled by default in the settings.
              'access' => array(
                'fasttoggle_node_status_access',
              ),
              // An access control function.
              'labels' => array(
                // The labels that are displayed for each state / label type.
                FASTTOGGLE_LABEL_ACTION => array(
                  0 => t('publish'),
                  1 => t('unpublish'),
                ),
                FASTTOGGLE_LABEL_STATUS => array(
                  0 => t('not published'),
                  1 => t('published'),
                ),
              ),
            ),
            'sticky' => array(
              'description' => t('Sticky <small>(stays at the top of listings)</small>'),
              'default' => TRUE,
              'access' => array(
                'fasttoggle_node_sticky_access',
              ),
              'labels' => array(
                FASTTOGGLE_LABEL_ACTION => array(
                  0 => t('make sticky'),
                  1 => t('make unsticky'),
                ),
                FASTTOGGLE_LABEL_STATUS => array(
                  0 => t('not sticky'),
                  1 => t('sticky'),
                ),
              ),
            ),
            'promote' => array(
              'description' => t('Promoted <small>(visible on the front page)</small>'),
              'default' => TRUE,
              'access' => array(
                'fasttoggle_node_promote_access',
              ),
              'labels' => array(
                FASTTOGGLE_LABEL_ACTION => array(
                  0 => t('promote'),
                  1 => t('demote'),
                ),
                FASTTOGGLE_LABEL_STATUS => array(
                  0 => t('not promoted'),
                  1 => t('promoted'),
                ),
              ),
            ),
          ),
        ),
      ),
    ),
  );
  return $result;
}