public function PanelizerEntityDefault::hook_entity_update in Panelizer 7.2
Same name and namespace in other branches
- 7.3 plugins/entity/PanelizerEntityDefault.class.php \PanelizerEntityDefault::hook_entity_update()
Overrides PanelizerEntityInterface::hook_entity_update
File
- plugins/
entity/ PanelizerEntityDefault.class.php, line 789 - Base class for the Panelizer Entity plugin.
Class
- PanelizerEntityDefault
- Base class for the Panelizer Entity plugin.
Code
public function hook_entity_update($entity) {
list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
if (!$this
->is_panelized($bundle)) {
return;
}
// If there's no panelizer information on the entity then there is nothing to do.
if (empty($entity->panelizer)) {
return;
}
if ($this->supports_revisions) {
if (empty($entity->panelizer->revision_id) || $entity->panelizer->revision_id != $revision_id) {
$update = array();
}
else {
$update = array(
'entity_type',
'revision_id',
);
}
}
else {
if (empty($entity->panelizer->entity_id)) {
$update = array();
}
else {
$update = array(
'entity_type',
'entity_id',
);
}
}
// The editor will set this flag if the display is modified. This lets
// us know if we need to clone a new display or not.
// NOTE: This means that when exporting or deploying, we need to be sure
// to set the display_is_modified flag to ensure this gets written.
if (!empty($entity->panelizer->display_is_modified)) {
// If this is a new entry or the entry is using a display from a default,
// clone the display.
if (!$update || empty($entity->panelizer->did)) {
$panelizer = $this
->clone_panelizer($entity->panelizer, $entity);
}
else {
$panelizer = $entity->panelizer;
}
// First write the display
panels_save_display($panelizer->display);
// Make sure we have the did.
$panelizer->did = $panelizer->display->did;
// Ensure that we always write this as NULL when we have our own panel:
$panelizer->name = NULL;
// And write the new record.
return drupal_write_record('panelizer_entity', $panelizer, $update);
}
else {
$entity->panelizer->entity_type = $this->entity_type;
$entity->panelizer->entity_id = $entity_id;
// The (int) ensures that entities that do not support revisions work
// since the revision_id cannot be NULL.
$entity->panelizer->revision_id = (int) $revision_id;
drupal_write_record('panelizer_entity', $entity->panelizer, $update);
}
}