2012-12-21 17:03:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Provides in-place content editing functionality for fields.
|
|
|
|
*
|
|
|
|
* The Edit module makes content editable in-place. Rather than having to visit
|
|
|
|
* a separate page to edit content, it may be edited in-place.
|
|
|
|
*
|
|
|
|
* Technically, this module adds classes and data- attributes to fields and
|
|
|
|
* entities, enabling them for in-place editing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Drupal\Core\Entity\EntityInterface;
|
|
|
|
use Drupal\edit\Form\EditFieldForm;
|
2013-01-09 23:58:39 +00:00
|
|
|
use Drupal\Component\Utility\NestedArray;
|
2012-12-21 17:03:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_custom_theme().
|
|
|
|
*
|
|
|
|
* @todo Add an event subscriber to the Ajax system to automatically set the
|
|
|
|
* base page theme for all Ajax requests, and then remove this one off.
|
|
|
|
*/
|
|
|
|
function edit_custom_theme() {
|
|
|
|
if (substr(current_path(), 0, 5) === 'edit/') {
|
|
|
|
return ajax_base_page_theme();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_permission().
|
|
|
|
*/
|
|
|
|
function edit_permission() {
|
|
|
|
return array(
|
|
|
|
'access in-place editing' => array(
|
|
|
|
'title' => t('Access in-place editing'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-14 19:02:48 +00:00
|
|
|
* Implements hook_page_build().
|
2013-02-12 21:46:04 +00:00
|
|
|
*
|
2013-05-14 19:02:48 +00:00
|
|
|
* Adds the edit library to the page for any user who has the 'access in-place
|
|
|
|
* editing' permission.
|
2012-12-21 17:03:57 +00:00
|
|
|
*/
|
2013-05-14 19:02:48 +00:00
|
|
|
function edit_page_build(&$page) {
|
2012-12-21 17:03:57 +00:00
|
|
|
if (!user_access('access in-place editing')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-14 19:02:48 +00:00
|
|
|
$page['#attached']['js'][] = array(
|
|
|
|
'type' => 'setting',
|
|
|
|
'data' => array('edit' => array(
|
|
|
|
'fieldFormURL' => url('edit/form/!entity_type/!id/!field_name/!langcode/!view_mode'),
|
|
|
|
'context' => 'body',
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
$page['#attached']['library'][] = array('edit', 'edit');
|
2012-12-21 17:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-23 14:48:34 +00:00
|
|
|
* Implements hook_library_info().
|
2012-12-21 17:03:57 +00:00
|
|
|
*/
|
|
|
|
function edit_library_info() {
|
|
|
|
$path = drupal_get_path('module', 'edit');
|
|
|
|
$options = array(
|
|
|
|
'scope' => 'footer',
|
|
|
|
);
|
|
|
|
$libraries['edit'] = array(
|
|
|
|
'title' => 'Edit: in-place editing',
|
|
|
|
'version' => VERSION,
|
|
|
|
'js' => array(
|
|
|
|
// Core.
|
|
|
|
$path . '/js/edit.js' => $options,
|
|
|
|
// Models.
|
2013-05-14 19:02:48 +00:00
|
|
|
$path . '/js/models/AppModel.js' => $options,
|
|
|
|
$path . '/js/models/EntityModel.js' => $options,
|
|
|
|
$path . '/js/models/FieldModel.js' => $options,
|
|
|
|
$path . '/js/models/EditorModel.js' => $options,
|
2012-12-21 17:03:57 +00:00
|
|
|
// Views.
|
2013-05-14 19:02:48 +00:00
|
|
|
$path . '/js/views/AppView.js' => $options,
|
|
|
|
$path . '/js/views/EditorDecorationView.js' => $options,
|
|
|
|
$path . '/js/views/ContextualLinkView.js' => $options,
|
|
|
|
$path . '/js/views/ModalView.js' => $options,
|
|
|
|
$path . '/js/views/FieldToolbarView.js' => $options,
|
|
|
|
$path . '/js/views/EditorView.js' => $options,
|
2012-12-21 17:03:57 +00:00
|
|
|
// Other.
|
|
|
|
$path . '/js/util.js' => $options,
|
|
|
|
$path . '/js/theme.js' => $options,
|
|
|
|
),
|
|
|
|
'css' => array(
|
|
|
|
$path . '/css/edit.css' => array(),
|
|
|
|
),
|
|
|
|
'dependencies' => array(
|
|
|
|
array('system', 'jquery'),
|
|
|
|
array('system', 'underscore'),
|
|
|
|
array('system', 'backbone'),
|
|
|
|
array('system', 'jquery.form'),
|
|
|
|
array('system', 'drupal.form'),
|
|
|
|
array('system', 'drupal.ajax'),
|
|
|
|
array('system', 'drupalSettings'),
|
|
|
|
),
|
|
|
|
);
|
2013-03-20 18:38:12 +00:00
|
|
|
$libraries['edit.editorWidget.form'] = array(
|
2013-05-14 19:02:48 +00:00
|
|
|
'title' => 'Form in-place editor',
|
2013-01-14 22:25:05 +00:00
|
|
|
'version' => VERSION,
|
|
|
|
'js' => array(
|
2013-05-14 19:02:48 +00:00
|
|
|
$path . '/js/editors/formEditor.js' => $options,
|
2013-01-14 22:25:05 +00:00
|
|
|
),
|
|
|
|
'dependencies' => array(
|
|
|
|
array('edit', 'edit'),
|
|
|
|
),
|
|
|
|
);
|
2013-03-20 18:38:12 +00:00
|
|
|
$libraries['edit.editorWidget.direct'] = array(
|
2013-05-14 19:02:48 +00:00
|
|
|
'title' => 'Direct in-place editor',
|
2013-01-14 22:25:05 +00:00
|
|
|
'version' => VERSION,
|
|
|
|
'js' => array(
|
2013-05-14 19:02:48 +00:00
|
|
|
$path . '/js/editors/directEditor.js' => $options,
|
2013-01-14 22:25:05 +00:00
|
|
|
),
|
|
|
|
'dependencies' => array(
|
|
|
|
array('edit', 'edit'),
|
|
|
|
),
|
|
|
|
);
|
2012-12-21 17:03:57 +00:00
|
|
|
|
|
|
|
return $libraries;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_HOOK() for field.tpl.php.
|
|
|
|
*/
|
|
|
|
function edit_preprocess_field(&$variables) {
|
|
|
|
$element = $variables['element'];
|
|
|
|
$entity = $element['#object'];
|
2013-01-14 22:25:05 +00:00
|
|
|
$variables['attributes']['data-edit-id'] = $entity->entityType() . '/' . $entity->id() . '/' . $element['#field_name'] . '/' . $element['#language'] . '/' . $element['#view_mode'];
|
2012-12-21 17:03:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 21:46:04 +00:00
|
|
|
/**
|
Issue #1898432 by WebDevDude, steveoliver, vlad.dancer, jenlampton, pixelmord, Fabianx, iztok, EVIIILJ, jwilson3, c4rl, Cottser: Convert node module to Twig.
2013-05-24 17:13:55 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for node.html.twig.
|
2013-02-12 21:46:04 +00:00
|
|
|
*
|
2013-05-04 07:18:03 +00:00
|
|
|
* @todo Remove this, handle in generic way: http://drupal.org/node/1972514.
|
2013-02-12 21:46:04 +00:00
|
|
|
*/
|
|
|
|
function edit_preprocess_node(&$variables) {
|
|
|
|
$node = $variables['elements']['#node'];
|
|
|
|
$variables['attributes']['data-edit-entity'] = 'node/' . $node->nid;
|
|
|
|
}
|
|
|
|
|
2013-05-04 07:18:03 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_HOOK() for taxonomy-term.tpl.php.
|
|
|
|
*
|
|
|
|
* @todo Remove this, handle in generic way: http://drupal.org/node/1972514.
|
|
|
|
*/
|
|
|
|
function edit_preprocess_taxonomy_term(&$variables) {
|
|
|
|
$term = $variables['elements']['#term'];
|
|
|
|
$variables['attributes']['data-edit-entity'] = 'taxonomy_term/' . $term->id();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
Issue #1898034 by Cottser, jenlampton, joelpittet, Shawn DeArmond, idflood, Hydra, artofeclipse, rich.yumul, chrisjlee, gnuget, c4rl, thund3rbox: block.module - Convert PHPTemplate templates to Twig.
2013-05-24 17:14:30 +00:00
|
|
|
* Implements hook_preprocess_HOOK() for block.html.twig.
|
2013-05-04 07:18:03 +00:00
|
|
|
*
|
|
|
|
* @todo Remove this, handle in generic way: http://drupal.org/node/1972514.
|
|
|
|
*/
|
|
|
|
function edit_preprocess_block(&$variables) {
|
|
|
|
if (isset($variables['elements']['content']['#custom_block'])) {
|
|
|
|
$custom_block = $variables['elements']['content']['#custom_block'];
|
|
|
|
$variables['attributes']['data-edit-entity'] = 'custom_block/' . $custom_block->id();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-21 17:03:57 +00:00
|
|
|
/**
|
|
|
|
* Form constructor for the field editing form.
|
|
|
|
*
|
|
|
|
* @ingroup forms
|
|
|
|
*/
|
|
|
|
function edit_field_form(array $form, array &$form_state, EntityInterface $entity, $field_name) {
|
|
|
|
$form_handler = new EditFieldForm();
|
|
|
|
return $form_handler->build($form, $form_state, $entity, $field_name);
|
|
|
|
}
|