You are here

final public function PartyDataBase::detachEntityByDelta in Party 8.2

Detatch an entity by delta

This method cannot be overloaded and any extensions of this class can make use of PartyDefaultDataSet::preAttach() and PartyDefaultDataSet::postAttach() to perform any additional logic required.

Parameters

int $delta: The delta of the entity to detach

bool $return: Whether you want to return the detached entity or $this for chaining. Defaults to FALSE.

Return value

object|$this Depending on $return, either the detached entity or this for chaining.

See also

PartyDefaultDataSet::preDetach()

PartyDefaultDataSet::postDetach()

1 call to PartyDataBase::detachEntityByDelta()
PartyDataBase::detachEntity in lib/Drupal/party/Plugin/PartyDataBase.php
Detach an entity

File

lib/Drupal/party/Plugin/PartyDataBase.php, line 519
Contains \Drupal\party\Plugin\PartyDataBase.

Class

PartyDataBase
Class PartyDataBase

Namespace

Drupal\party\Plugin

Code

public final function detachEntityByDelta($delta, $return = FALSE) {

  // Fire any pre attach logic
  $this
    ->preDetach($delta);
  if (isset($this->entities[$delta])) {

    // Get our entity for returning if requested
    $entity = $this->entities[$delta];

    // Detach our entity
    unset($this->entities[$delta]);

    // Reset our numeric indexes
    $this->entities = array_values($this->entities);
  }
  else {

    // Can't return the entity if it didn't exist
    $entity = FALSE;
  }

  // Fire any post attach logic
  $this
    ->postDetach($delta);
  if ($return) {
    return $entity;
  }
  else {
    return $this;
  }
}