You are here

function block_edit_visible in Block edit 6

Calculate whether block edit links should be visible.

2 calls to block_edit_visible()
block_edit_preprocess_block in ./block_edit.module
Preprocess function to add the block edit links to blocks by concatenating with the content variable.
block_edit_preprocess_node in ./block_edit.module
Preprocess function to add the node edit links to nodes by concatenating with the content variable.

File

./block_edit.module, line 236
Adds edit links to blocks and nodes to make administration more intuitive.

Code

function block_edit_visible($type, $vars) {
  switch ($type) {
    case 'node':
      if (!user_access('view node edit links')) {
        return FALSE;
      }

      // Enable node edit links setting.
      if (!variable_get('block_edit_node_links', 1)) {
        return FALSE;
      }

      // Page specific visibility settings.
      if (!block_edit_visibility('node')) {
        return FALSE;
      }
      $node = $vars['node'];

      // Shouldn't appear in other build modes, such as search indexing and
      // results, RSS, print, preview, etc.
      if (isset($node->build_mode) && $node->build_mode !== NODE_BUILD_NORMAL) {
        return FALSE;
      }

      // Content type settings.
      $allowed_nodes = variable_get('block_edit_content_types', array_combine(array_keys(node_get_types('names')), array_keys(node_get_types('names'))));
      if ($allowed_nodes[$node->type] !== $node->type) {
        return FALSE;
      }

      // Display mode settings.
      if (!block_edit_display_types($vars)) {
        return FALSE;
      }
      break;
    case 'block':
      if (!user_access('view block edit links')) {
        return FALSE;
      }

      // Enable block edit links setting.
      if (!variable_get('block_edit_block_links', 1)) {
        return FALSE;
      }

      // Role-based permission check.
      if (!user_access('administer blocks') && !user_access('administer menu')) {
        return FALSE;
      }

      // Page specific visibility settings.
      if (!block_edit_visibility('block')) {
        return FALSE;
      }
      break;
  }
  return TRUE;
}