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;
|
2013-06-12 15:57:44 +00:00
|
|
|
use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
|
2012-12-21 17:03:57 +00:00
|
|
|
|
|
|
|
/**
|
2013-06-10 13:03:14 +00:00
|
|
|
* Implements hook_menu().
|
2012-12-21 17:03:57 +00:00
|
|
|
*/
|
2013-06-10 13:03:14 +00:00
|
|
|
function edit_menu() {
|
|
|
|
// @todo Remove these menu items in http://drupal.org/node/1954892 when theme
|
|
|
|
// callbacks are replaced with something else.
|
|
|
|
$items['edit/metadata'] = array(
|
|
|
|
'route_name' => 'edit_metadata',
|
|
|
|
'theme callback' => 'ajax_base_page_theme',
|
|
|
|
);
|
|
|
|
$items['edit/form/%/%/%/%/%'] = array(
|
|
|
|
'route_name' => 'edit_field_form',
|
|
|
|
'theme callback' => 'ajax_base_page_theme',
|
|
|
|
);
|
|
|
|
|
|
|
|
return $items;
|
2012-12-21 17:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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(
|
2013-06-07 10:48:55 +00:00
|
|
|
$path . '/css/edit.module.css' => array(),
|
2012-12-21 17:03:57 +00:00
|
|
|
),
|
|
|
|
'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
|
|
|
/**
|
2013-06-12 15:57:44 +00:00
|
|
|
* Implements hook_entity_view_alter().
|
2013-05-04 07:18:03 +00:00
|
|
|
*/
|
2013-06-12 15:57:44 +00:00
|
|
|
function edit_entity_view_alter(&$build, EntityInterface $entity, EntityDisplay $display) {
|
|
|
|
$build['#attributes']['data-edit-entity'] = $entity->entityType() . '/' . $entity->id();
|
2013-05-04 07:18:03 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|