core/modules/edit/lib/Drupal/edit/EditController.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/core/modules/edit/lib/Drupal/edit/EditController.php b/core/modules/edit/lib/Drupal/edit/EditController.php index a242238..412c16a 100644 --- a/core/modules/edit/lib/Drupal/edit/EditController.php +++ b/core/modules/edit/lib/Drupal/edit/EditController.php @@ -235,8 +235,14 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view $entity = $this->tempStoreFactory->get('edit')->get($entity->uuid()); // Closure to render the field given a view mode. - $render_field_in_view_mode = function ($view_mode_id) use ($entity, $field_name, $langcode) { - return $this->renderField($entity, $field_name, $langcode, $view_mode_id); + // @todo Drupal 8 will — but does not yet — require PHP 5.4: + // https://drupal.org/node/2152073. One of the new features in that + // version is $this support for closures. See + // http://php.net/manual/en/migration54.new-features.php. + // That will allow us to get rid of this ugly $that = $this mess. + $that = $this; + $render_field_in_view_mode = function ($view_mode_id) use ($entity, $field_name, $langcode, $that) { + return $that->renderField($entity, $field_name, $langcode, $view_mode_id); }; // Re-render the updated field. @@ -294,8 +300,13 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view * Rendered HTML. * * @see hook_edit_render_field() + * + * @todo Until Drupal 8 requires PHP 5.4, we cannot call $this inside a + * closure (see higher), which also means anything called from a closure + * must be public. So, until https://drupal.org/node/2152073 lands, use + * "public" instead of "protected". */ - protected function renderField(EntityInterface $entity, $field_name, $langcode, $view_mode_id) { + public function renderField(EntityInterface $entity, $field_name, $langcode, $view_mode_id) { $entity_view_mode_ids = array_keys(entity_get_view_modes($entity->entityType())); if (in_array($view_mode_id, $entity_view_mode_ids)) { $output = field_view_field($entity, $field_name, $view_mode_id, $langcode);