* // rules will be used.
* $build = $view_builder->view($entity, 'view_mode_name', $language->getId());
* // $build is a render array.
- * $rendered = drupal_render($build);
+ * $rendered = \Drupal::service('renderer')->render($build);
* @endcode
*
* @section sec_access Access checking on entities
\Drupal::logger('example')->info('ENTITY_TYPE created: @label', ['@label' => $entity->label()]);
}
+/**
+ * Respond to entity revision creation.
+ *
+ * @param \Drupal\Core\Entity\EntityInterface $new_revision
+ * The new revision that was created.
+ * @param \Drupal\Core\Entity\EntityInterface $entity
+ * The original entity that was used to create the revision from.
+ * @param bool|null $keep_untranslatable_fields
+ * Whether untranslatable field values were kept (TRUE) or copied from the
+ * default revision (FALSE) when generating a merged revision. If no value was
+ * explicitly specified (NULL), a default value of TRUE should be assumed if
+ * the provided entity is the default translation and untranslatable fields
+ * should only affect the default translation, FALSE otherwise.
+ *
+ * @ingroup entity_crud
+ * @see \Drupal\Core\Entity\RevisionableStorageInterface::createRevision()
+ * @see \Drupal\Core\Entity\TranslatableRevisionableStorageInterface::createRevision()
+ */
+function hook_entity_revision_create(Drupal\Core\Entity\EntityInterface $new_revision, Drupal\Core\Entity\EntityInterface $entity, $keep_untranslatable_fields) {
+ // Retain the value from an untranslatable field, which are by default
+ // synchronized from the default revision.
+ $new_revision->set('untranslatable_field', $entity->get('untranslatable_field'));
+}
+
+/**
+ * Respond to entity revision creation.
+ *
+ * @param \Drupal\Core\Entity\EntityInterface $new_revision
+ * The new revision that was created.
+ * @param \Drupal\Core\Entity\EntityInterface $entity
+ * The original entity that was used to create the revision from.
+ * @param bool|null $keep_untranslatable_fields
+ * Whether untranslatable field values were kept (TRUE) or copied from the
+ * default revision (FALSE) when generating a merged revision. If no value was
+ * explicitly specified (NULL), a default value of TRUE should be assumed if
+ * the provided entity is the default translation and untranslatable fields
+ * should only affect the default translation, FALSE otherwise.
+ *
+ * @ingroup entity_crud
+ * @see \Drupal\Core\Entity\RevisionableStorageInterface::createRevision()
+ * @see \Drupal\Core\Entity\TranslatableRevisionableStorageInterface::createRevision()
+ */
+function hook_ENTITY_TYPE_revision_create(Drupal\Core\Entity\EntityInterface $new_revision, Drupal\Core\Entity\EntityInterface $entity, $keep_untranslatable_fields) {
+ // Retain the value from an untranslatable field, which are by default
+ // synchronized from the default revision.
+ $new_revision->set('untranslatable_field', $entity->get('untranslatable_field'));
+}
+
/**
* Act on entities when loaded.
*
* @param &$build
* A renderable array representing the entity content. The module may add
* elements to $build prior to rendering. The structure of $build is a
- * renderable array as expected by drupal_render().
+ * renderable array as expected by
+ * \Drupal\Core\Render\RendererInterface::render().
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
* @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display
* @param &$build
* A renderable array representing the entity content. The module may add
* elements to $build prior to rendering. The structure of $build is a
- * renderable array as expected by drupal_render().
+ * renderable array as expected by
+ * \Drupal\Core\Render\RendererInterface::render().
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
* @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display
* @param string $view_mode
* The view_mode that is to be used to display the entity.
*
- * @see drupal_render()
+ * @see \Drupal\Core\Render\RendererInterface::render()
* @see \Drupal\Core\Entity\EntityViewBuilder
* @see hook_entity_build_defaults_alter()
*
* @param string $view_mode
* The view_mode that is to be used to display the entity.
*
- * @see drupal_render()
+ * @see \Drupal\Core\Render\RendererInterface::render()
* @see \Drupal\Core\Entity\EntityViewBuilder
* @see hook_ENTITY_TYPE_build_defaults_alter()
*
* @param \Drupal\Core\Session\AccountInterface $account
* The user account to check.
* @param \Drupal\Core\Field\FieldItemListInterface $items
- * (optional) The entity field object on which the operation is to be
- * performed.
+ * (optional) The entity field object for which to check access, or NULL if
+ * access is checked for the field definition, without any specific value
+ * available. Defaults to NULL.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.