You are here

function entity_hierarchy_views_update in Entity Reference Hierarchy 8

Update the given embedded view.

2 calls to entity_hierarchy_views_update()
entity_hierarchy_views_node_insert in entity_hierarchy_views/entity_hierarchy_views.module
Implements hook_ENTITY_TYPE_insert().
entity_hierarchy_views_node_update in entity_hierarchy_views/entity_hierarchy_views.module
Implements hook_ENTITY_TYPE_update().

File

entity_hierarchy_views/entity_hierarchy_views.module, line 224
Contains entity_hierarchy_views.module..

Code

function entity_hierarchy_views_update($node) {
  if (\Drupal::currentUser()
    ->hasPermission('edit embedded child view')) {
    db_delete('entity_hierarchy_views')
      ->condition('nid', $node
      ->id())
      ->execute();
    if (!empty($node->nh_children_view)) {
      $parts = explode(':', $node->nh_children_view);
      if (!empty($parts[0])) {
        $view = $parts[0];
      }
      if (!empty($parts[1])) {
        $display = $parts[1];
      }
      else {

        // If this update is not from a form submit then the display may be stored separately.
        $display = !empty($node->nh_children_view_display) ? $node->nh_children_view_display : 'default';
      }
      $id = db_insert('entity_hierarchy_views')
        ->fields(array(
        'nid' => $node
          ->id(),
        'nh_children_view' => $view,
        'nh_children_view_display' => $display,
      ))
        ->execute();
    }
  }
}