|
|
@@ -797,15 +797,20 @@ class TreeBehavior extends Behavior
|
|
|
/**
|
|
|
* Returns the depth level of a node in the tree.
|
|
|
*
|
|
|
- * @param int|string $id Primary key of the node.
|
|
|
+ * @param int|string|\Cake\Datasource\EntityInterface $entity The entity or primary key get the level of.
|
|
|
* @return int|bool Integer of the level or false if the node does not exist.
|
|
|
*/
|
|
|
- public function getLevel($id)
|
|
|
+ public function getLevel($entity)
|
|
|
{
|
|
|
+ $primaryKey = $this->_getPrimaryKey();
|
|
|
+ $id = $entity;
|
|
|
+ if (!is_scalar($entity)) {
|
|
|
+ $id = $entity->get($primaryKey);
|
|
|
+ }
|
|
|
$config = $this->config();
|
|
|
$entity = $this->_table->find('all')
|
|
|
->select([$config['left'], $config['right']])
|
|
|
- ->where([$this->_getPrimaryKey() => $id])
|
|
|
+ ->where([$primaryKey => $id])
|
|
|
->first();
|
|
|
|
|
|
if ($entity === null) {
|