You are here

function quickedit_ckeditor_get_untransformed_text in Quick Edit 7

Page callback: Returns an Ajax response to render a text field without transformation filters.

Parameters

$entity: The entity being edited.

string $field_name: The name of the field that is being edited.

string $langcode: The name of the language for which the field is being edited.

string $view_mode: The view mode the field should be rerendered in.

Return value

The Ajax response.

See also

Drupal 8's EditorController::getUntransformedText()

1 string reference to 'quickedit_ckeditor_get_untransformed_text'
quickedit_menu in ./quickedit.module
Implements hook_menu().

File

includes/pages.inc, line 363
AJAX endpoint to retrieve & save subforms for fields and re-render fields.

Code

function quickedit_ckeditor_get_untransformed_text($entity_type, $entity_id, $field_name, $langcode = NULL, $view_mode = NULL) {
  $commands = array();
  $entity = entity_load_single($entity_type, $entity_id);
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);

  // Ensure the user is allowed to edit this field.
  module_load_include('php', 'quickedit', 'includes/EditEntityFieldAccessCheck');
  $accessChecker = new EditEntityFieldAccessCheck();
  if (!$accessChecker
    ->accessEditEntityField($entity_type, $entity, $field_name)) {
    return MENU_ACCESS_DENIED;
  }

  // Render the field in our custom display mode; retrieve the re-rendered
  // markup, this is what we're after.
  $field_output = field_view_field($entity_type, $entity, $field_name, 'quickedit-render-without-transformation-filters', $langcode);
  $output = $field_output[0]['#markup'];
  $commands[] = array(
    'command' => 'quickeditCKEditorGetUntransformedText',
    'id' => "{$entity_type}/{$id}/{$field_name}/{$langcode}/{$view_mode}",
    'data' => $output,
  );
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}