Skip to content
Snippets Groups Projects
Commit 3076bee4 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #1996378 by Wim Leers: Edit broken because of #1043198 and routing...

Issue #1996378 by Wim Leers: Edit broken because of #1043198 and routing system bug + missing test coverage.
parent ff6e1eea
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ edit_metadata:
_permission: 'access in-place editing'
edit_field_form:
pattern: '/edit/form/{entity_type}/{entity}/{field_name}/{langcode}/{view_mode}'
pattern: '/edit/form/{entity_type}/{entity}/{field_name}/{langcode}/{view_mode_id}'
defaults:
_controller: '\Drupal\edit\EditController::fieldForm'
requirements:
......
......@@ -91,12 +91,12 @@ public function metadata(Request $request) {
* The name of the field that is being edited.
* @param string $langcode
* The name of the language for which the field is being edited.
* @param string $view_mode
* @param string $view_mode_id
* The view mode the field should be rerendered in.
* @return \Drupal\Core\Ajax\AjaxResponse
* The Ajax response.
*/
public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view_mode) {
public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view_mode_id) {
$response = new AjaxResponse();
$form_state = array(
......@@ -112,7 +112,7 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view
$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);
$output = field_view_field($entity, $field_name, $view_mode_id, $langcode);
$response->addCommand(new FieldFormSavedCommand(drupal_render($output)));
}
......
......@@ -10,6 +10,7 @@
use Drupal\simpletest\WebTestBase;
use Drupal\edit\Ajax\MetadataCommand;
use Drupal\Core\Ajax\AppendCommand;
use Drupal\Component\Utility\Unicode;
/**
* Tests loading of Edit and lazy-loading of in-place editors.
......@@ -137,6 +138,15 @@ function testUserWithPermission() {
)
));
$this->assertIdentical($command->render(), $ajax_commands[2], 'The Edit metadata command contains the expected metadata.');
// Retrieving the form for this field should result in a 200 response,
// containing only an editFieldForm command.
$response = $this->retrieveFieldForm('node/1/body/und/full');
$this->assertResponse(200);
$ajax_commands = drupal_json_decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in three AJAX commands.');
$this->assertIdentical('editFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is an editFieldForm command.');
$this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The editFieldForm command contains a form.');
}
/**
......@@ -165,7 +175,51 @@ protected function retrieveMetadata($ids) {
}
$post = implode('&', $post);
// Add extra information to the POST data as ajax.js does.
// Perform HTTP request.
return $this->curlExec(array(
CURLOPT_URL => url('edit/metadata', array('absolute' => TRUE)),
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $post . $this->getAjaxPageStatePostData(),
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
),
));
}
/**
* Retrieve field form from the server. May also result in additional
* JavaScript settings and CSS/JS being loaded.
*
* @param string $field_id
* An Edit field ID.
*
* @return string
* The response body.
*/
protected function retrieveFieldForm($field_id) {
// Build & serialize POST value.
$post = urlencode('nocssjs') . '=' . urlencode('true');
// Perform HTTP request.
return $this->curlExec(array(
CURLOPT_URL => url('edit/form/' . $field_id, array('absolute' => TRUE)),
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $post . $this->getAjaxPageStatePostData(),
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
),
));
}
/**
* Get extra information to the POST data as ajax.js does.
*
* @return string
* Additional post data.
*/
protected function getAjaxPageStatePostData() {
$extra_post = '';
$drupal_settings = $this->drupalSettings;
if (isset($drupal_settings['ajaxPageState'])) {
......@@ -178,16 +232,6 @@ protected function retrieveMetadata($ids) {
$extra_post .= '&' . urlencode("ajax_page_state[js][$key]") . '=1';
}
}
// Perform HTTP request.
return $this->curlExec(array(
CURLOPT_URL => url('edit/metadata', array('absolute' => TRUE)),
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $post . $extra_post,
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
),
));
}
return $extra_post;
}
}
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