You are here

public function ViewsBulkOperationsViewData::getEntity in Views Bulk Operations (VBO) 8

Same name and namespace in other branches
  1. 8.3 src/Service/ViewsBulkOperationsViewData.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData::getEntity()
  2. 8.2 src/Service/ViewsBulkOperationsViewData.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData::getEntity()
  3. 4.0.x src/Service/ViewsBulkOperationsViewData.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData::getEntity()

Get entity from views row.

Parameters

\Drupal\views\ResultRow $row: Views row object.

Return value

\Drupal\Core\Entity\EntityInterface An entity object.

Overrides ViewsBulkOperationsViewDataInterface::getEntity

File

src/Service/ViewsBulkOperationsViewData.php, line 141

Class

ViewsBulkOperationsViewData
Gets Views data needed by VBO.

Namespace

Drupal\views_bulk_operations\Service

Code

public function getEntity(ResultRow $row) {
  if (!empty($this->entityGetter['file'])) {
    require_once $this->entityGetter['file'];
  }
  if (is_callable($this->entityGetter['callable'])) {
    return call_user_func($this->entityGetter['callable'], $row, $this->relationship, $this->view);
  }
  else {
    if (is_array($this->entityGetter['callable'])) {
      if (is_object($this->entityGetter['callable'][0])) {
        $info = get_class($this->entityGetter['callable'][0]);
      }
      else {
        $info = $this->entityGetter['callable'][0];
      }
      $info .= '::' . $this->entityGetter['callable'][1];
    }
    else {
      $info = $this->entityGetter['callable'];
    }
    throw new \Exception(sprintf("Entity getter method %s doesn't exist.", $info));
  }
}