<?php
use Drupal\Core\Entity\EntityInterface;
use Drupal\edit\Form\EditFieldForm;
use Drupal\Component\Utility\NestedArray;
use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
function edit_menu() {
$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;
}
function edit_permission() {
return array(
'access in-place editing' => array(
'title' => t('Access in-place editing'),
),
);
}
function edit_page_build(&$page) {
if (!user_access('access in-place editing')) {
return;
}
$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',
);
}
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(
$path . '/js/edit.js' => $options,
$path . '/js/models/AppModel.js' => $options,
$path . '/js/models/EntityModel.js' => $options,
$path . '/js/models/FieldModel.js' => $options,
$path . '/js/models/EditorModel.js' => $options,
$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,
$path . '/js/util.js' => $options,
$path . '/js/theme.js' => $options,
),
'css' => array(
$path . '/css/edit.module.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',
),
),
);
$libraries['edit.editorWidget.form'] = array(
'title' => 'Form in-place editor',
'version' => VERSION,
'js' => array(
$path . '/js/editors/formEditor.js' => $options,
),
'dependencies' => array(
array(
'edit',
'edit',
),
),
);
$libraries['edit.editorWidget.direct'] = array(
'title' => 'Direct in-place editor',
'version' => VERSION,
'js' => array(
$path . '/js/editors/directEditor.js' => $options,
),
'dependencies' => array(
array(
'edit',
'edit',
),
),
);
return $libraries;
}
function edit_field_formatter_info_alter(&$info) {
foreach ($info as $key => $settings) {
if (empty($settings['edit'])) {
$info[$key]['edit'] = array(
'editor' => 'form',
);
}
}
}
function edit_preprocess_field(&$variables) {
$element = $variables['element'];
$entity = $element['#object'];
$variables['attributes']['data-edit-id'] = $entity
->entityType() . '/' . $entity
->id() . '/' . $element['#field_name'] . '/' . $element['#language'] . '/' . $element['#view_mode'];
}
function edit_entity_view_alter(&$build, EntityInterface $entity, EntityDisplay $display) {
$build['#attributes']['data-edit-entity'] = $entity
->entityType() . '/' . $entity
->id();
}
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);
}