You are here

public function PanelizerEntityDefault::hook_entity_insert in Panelizer 7.2

Same name and namespace in other branches
  1. 7.3 plugins/entity/PanelizerEntityDefault.class.php \PanelizerEntityDefault::hook_entity_insert()

Overrides PanelizerEntityInterface::hook_entity_insert

File

plugins/entity/PanelizerEntityDefault.class.php, line 751
Base class for the Panelizer Entity plugin.

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

public function hook_entity_insert($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;
  }

  // On entity insert, we only write the display if it is not a default. That
  // probably means it came from an export or deploy or something along
  // those lines.
  if (empty($entity->panelizer->name) && !empty($entity->panelizer->display)) {
    $panelizer = $this
      ->clone_panelizer($entity->panelizer, $entity);

    // First write the display
    panels_save_display($panelizer->display);

    // Make sure we have the new did.
    $panelizer->did = $panelizer->display->did;

    // And write the new record.
    return drupal_write_record('panelizer_entity', $panelizer);
  }
  else {

    // We write the panelizer record to record which name is being used.
    // And ensure the did is NULL:
    $entity->panelizer->did = NULL;
    $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;
    return drupal_write_record('panelizer_entity', $entity->panelizer);
  }
}