You are here

public function DraggableViews::getIndex in DraggableViews 8

Same name and namespace in other branches
  1. 2.0.x src/DraggableViews.php \Drupal\draggableviews\DraggableViews::getIndex()

Get index by id.

2 calls to DraggableViews::getIndex()
DraggableViews::getAncestor in src/DraggableViews.php
Get ancestor by index.
DraggableViews::getDepth in src/DraggableViews.php
Get depth by index.

File

src/DraggableViews.php, line 34

Class

DraggableViews
Class DraggableViews.

Namespace

Drupal\draggableviews

Code

public function getIndex($id) {
  foreach ($this->view->result as $item) {
    if ($item->_entity instanceof Media) {

      // Media index name.
      $name = 'mid';
    }
    else {

      // Node index name. The default one.
      $name = 'nid';
    }
    if ($item->{$name} == $id) {
      return $item->index;
    }
  }
  return FALSE;
}