1 node.types.inc node_type_form_permissions($type)

Builds a matrix of node permissions for this node type.

Parameters

$type: Machine name for node type.

See also

node_type_form()

File

core/modules/node/node.types.inc, line 665
Content type editing user interface.

Code

function node_type_form_permissions($type) {
  // Retrieve role names for columns.
  $roles = user_roles(FALSE, NULL, TRUE);
  $admin_role = config_get('system.core', 'user_admin_role');
  $editor_role = config_get('system.core', 'user_editor_role');

  // Note that in node_theme(), the 'node_type_form_permissions' theme callback
  // reuses theme_user_admin_permissions(), to make it identical to the user
  // module permissions page.
  $form['#theme'] = array('node_type_form_permissions');

  // Wrap the table in a form element to make margins match other form elements.
  $form['#theme_wrappers'] = array('form_element');

  $form['roles'] = array(
    '#type' => 'value',
    '#value' => $roles,
  );

  // Render role/permission overview:
  $options = array();

  $default_perms = array(
    "create content" => array(
      'title' => t('Create new content'),
    ),
    "edit own content" => array(
      'title' => t('Edit own content'),
    ),
    "edit any content" => array(
      'title' => t('Edit any content'),
    ),
    "delete own content" => array(
      'title' => t('Delete own content'),
    ),
    "delete any content" => array(
      'title' => t('Delete any content'),
    ),
  );

  $permissions = !empty($type) ? node_list_permissions($type) : $default_perms;

  $status = array();
  foreach ($permissions as $perm => $perm_item) {
    // Fill in default values for the permission.
    $perm_item += array(
      'description' => '',
      'restrict access' => FALSE,
      'warning' => '',
    );
    $options[$perm] = '';
    $form['permission'][$perm] = array(
      '#type' => 'item',
      '#markup' => $perm_item['title'],
      '#description' => theme('user_permission_description', array('permission_item' => $perm_item)),
    );
    foreach ($roles as $role_name => $role) {
      // Builds arrays for checked boxes for each role. For new content types,
      // if user_admin_role and/or user_editor_role have been configured, then
      // select sensible permissions for these roles.
      if (in_array($perm, $role->permissions) || (!$type && ($role->name == $admin_role || $role->name == $editor_role))) {
        // Do not grant the 'delete any content' permission to editors by
        // default.
        if (!($role->name == $editor_role && $perm == 'delete any content')) {
          $status[$role_name][] = $perm;
        }
      }
    }
  }

  // Have to build checkboxes here after checkbox arrays are built.
  foreach ($roles as $role_name => $role) {
    $form['checkboxes'][$role_name] = array(
      '#type' => 'checkboxes',
      '#options' => $options,
      '#default_value' => isset($status[$role_name]) ? $status[$role_name] : array(),
      '#attributes' => array('class' => array('role-' . $role_name)),
    );
    $form['role_names'][$role_name] = array(
      '#markup' => check_plain($role->label),
      '#description' => filter_xss_admin($role->description),
      '#tree' => TRUE,
    );
  }

  $form['#attached']['js'][] = backdrop_get_path('module', 'user') . '/js/user.permissions.js';

  return $form;
}