Skip to content
Snippets Groups Projects
Commit d78f5a96 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1966704 by Wim Leers, jessebeach: In-place editing for taxonomy terms and custom blocks.

parent df851957
No related branches found
No related tags found
No related merge requests found
......@@ -150,13 +150,35 @@ function edit_preprocess_field(&$variables) {
/**
* Implements hook_preprocess_HOOK() for node.tpl.php.
*
* @todo Move towards hook_preprocess_entity() once that's available.
* @todo Remove this, handle in generic way: http://drupal.org/node/1972514.
*/
function edit_preprocess_node(&$variables) {
$node = $variables['elements']['#node'];
$variables['attributes']['data-edit-entity'] = 'node/' . $node->nid;
}
/**
* 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();
}
/**
* Implements hook_preprocess_HOOK() for block.tpl.php.
*
* @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();
}
}
/**
* Form constructor for the field editing form.
*
......
......@@ -41,10 +41,7 @@ public function access(Route $route, Request $request) {
* Implements EntityFieldAccessCheckInterface::accessEditEntityField().
*/
public function accessEditEntityField(EntityInterface $entity, $field_name) {
$entity_type = $entity->entityType();
// @todo Generalize to all entity types once http://drupal.org/node/1862750
// is done.
return ($entity_type == 'node' && node_access('update', $entity) && field_access('edit', $field_name, $entity_type, $entity));
return $entity->access('update') && field_access('edit', $field_name, $entity->entityType(), $entity);
}
/**
......
......@@ -110,6 +110,8 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view
// The form submission took care of saving the updated entity. Return the
// updated view of the field.
$entity = entity_load($form_state['entity']->entityType(), $form_state['entity']->id(), TRUE);
// @todo Remove when http://drupal.org/node/1346214 is complete.
$entity = $entity->getBCEntity();
$output = field_view_field($entity, $field_name, $view_mode, $langcode);
$response->addCommand(new FieldFormSavedCommand(drupal_render($output)));
......
......@@ -47,6 +47,9 @@ public function build(array $form, array &$form_state, EntityInterface $entity,
* Initialize the form state and the entity before the first form build.
*/
protected function init(array &$form_state, EntityInterface $entity, $field_name) {
// @todo Remove when http://drupal.org/node/1346214 is complete.
$entity = $entity->getBCEntity();
// @todo Rather than special-casing $node->revision, invoke prepareEdit()
// once http://drupal.org/node/1863258 lands.
if ($entity->entityType() == 'node') {
......
......@@ -54,6 +54,7 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco
protected function alterBuild(array &$build, EntityInterface $entity, EntityDisplay $display, $view_mode, $langcode = NULL) {
parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
$build['#attached']['css'][] = drupal_get_path('module', 'taxonomy') . '/taxonomy.css';
$build['#contextual_links']['taxonomy'] = array('taxonomy/term', array($entity->id()));
}
}
......@@ -291,6 +291,7 @@ function taxonomy_menu() {
'access callback' => 'entity_page_access',
'access arguments' => array(2, 'update'),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'weight' => 10,
'file' => 'taxonomy.admin.inc',
);
......@@ -301,6 +302,7 @@ function taxonomy_menu() {
'access callback' => 'entity_page_access',
'access arguments' => array(2, 'delete'),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE,
'weight' => 20,
'file' => 'taxonomy.admin.inc',
);
......
......@@ -36,9 +36,11 @@
?>
<div id="taxonomy-term-<?php print $term->id(); ?>"<?php print $attributes; ?>>
<?php print render($title_prefix); ?>
<?php if (!$page): ?>
<h2><a href="<?php print $url; ?>"><?php print $label; ?></a></h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
<div class="content">
<?php print render($content); ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment