You are here

function quickedit_preprocess_node in Quick Edit 7

Implements hook_preprocess_node().

Sets data-quickedit-entity-id attribute. Takes care of wrapping title, author, and created date for in-place editability.

File

./quickedit.module, line 526
Provides in-place content editing functionality for fields.

Code

function quickedit_preprocess_node(&$variables) {

  // If the user lacks the appropriate permission, return early to avoid
  // processing.
  if (!user_access('access in-place editing')) {
    return;
  }
  $entity_type = $variables['elements']['#entity_type'];
  $entity = $variables['elements']['#node'];
  $view_mode = $variables['elements']['#view_mode'];
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  $language = !empty($entity->language) ? $entity->language : LANGUAGE_NONE;
  $quickedit_id_suffix = "{$language}/{$view_mode}";

  // Set data-quickedit-entity-id attribute.
  $node = $variables['elements']['#node'];
  $variables['attributes_array']['data-quickedit-entity-id'] = 'node/' . $node->nid;

  // Pseudo-field: title.
  $node_type = node_type_get_type($bundle);
  if ($node_type->has_title && !empty($variables['title'])) {
    $variables['title'] = quickedit_wrap_pseudofield($variables['title'], "node/{$id}/title/{$quickedit_id_suffix}");
  }

  // Pseudo-fields: author (name) and created date (authoring date).
  if ($variables['display_submitted']) {
    $variables['name'] = quickedit_wrap_pseudofield($variables['name'], "node/{$id}/author/{$quickedit_id_suffix}", TRUE);
    $variables['date'] = quickedit_wrap_pseudofield($variables['date'], "node/{$id}/created/{$quickedit_id_suffix}", TRUE);
    $variables['submitted'] = t('Submitted by !username on !datetime', array(
      '!username' => $variables['name'],
      '!datetime' => $variables['date'],
    ));
  }
}