You are here

function theme_nodehierarchy_parent_selector in Node Hierarchy 7.2

Same name and namespace in other branches
  1. 6.3 nodehierarchy.module \theme_nodehierarchy_parent_selector()
  2. 6.2 nodehierarchy.module \theme_nodehierarchy_parent_selector()
  3. 7.4 nodehierarchy.admin.inc \theme_nodehierarchy_parent_selector()

Theme the parent selector pulldown, allowing for disabled options.

1 theme call to theme_nodehierarchy_parent_selector()
_nodehierarchy_get_parent_selector in ./nodehierarchy.module
Get the parent selector pulldown.

File

./nodehierarchy.module, line 1543
A module to make nodes hierarchical.

Code

function theme_nodehierarchy_parent_selector($variables) {
  $element = $variables['element'];
  element_set_attributes($element, array(
    'id',
    'name',
    'size',
  ));
  _form_set_class($element, array(
    'form-select',
  ));

  // Assemble the options.
  $options = '';
  foreach ($element['#options'] as $key => $option) {
    $attributes = '';

    // If the option represents a parent item (and not just the none option).
    if (!empty($element['#items'][$key]) && ($item = $element['#items'][$key])) {
      if ($element['#value'] == $key) {
        $attributes .= ' selected="selected"';
      }
      if ($item['disabled']) {
        $attributes .= ' disabled="disabled"';
        $option .= '*';
        $element['#description'] = t('Nodes marked with a * cannot be a parent for this node because they are not an allowed parent type.');
        if (user_access('administer hierarchy')) {
          $element['#description'] .= t(' To allow these nodes to be parents of this node, change the setting for that node type in the !settings', array(
            '!settings' => l(t('Node Hierarchy settings'), 'admin/config/nodehierarchy'),
          ));
        }
      }
    }
    $options .= '<option value="' . check_plain($key) . '"' . $attributes . '>' . $option . '</option>';
  }
  return '<select' . drupal_attributes($element['#attributes']) . '>' . $options . '</select>';
}