You are here

class SalesforceDeleteAllowedEvent in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 modules/salesforce_mapping/src/Event/SalesforceDeleteAllowedEvent.php \Drupal\salesforce_mapping\Event\SalesforceDeleteAllowedEvent

Delete allowed event.

Hierarchy

Expanded class hierarchy of SalesforceDeleteAllowedEvent

1 file declares its use of SalesforceDeleteAllowedEvent
DeleteHandler.php in modules/salesforce_pull/src/DeleteHandler.php

File

modules/salesforce_mapping/src/Event/SalesforceDeleteAllowedEvent.php, line 11

Namespace

Drupal\salesforce_mapping\Event
View source
class SalesforceDeleteAllowedEvent extends SalesforceBaseEvent {

  /**
   * Indicates whether delete is allowed to continue.
   *
   * @var bool
   */
  protected $deleteAllowed;

  /**
   * The mapped object.
   *
   * @var \Drupal\salesforce_mapping\Entity\MappedObjectInterface
   */
  protected $mappedObject;

  /**
   * The Drupal entity.
   *
   * @var \Drupal\Core\Entity\FieldableEntityInterface
   */
  protected $entity;

  /**
   * SalesforceDeleteAllowedEvent dispatched before deleting an entity.
   *
   * @param \Drupal\salesforce_mapping\Entity\MappedObjectInterface $mapped_object
   *   The mapped object.
   */
  public function __construct(MappedObjectInterface $mapped_object) {
    $this->mappedObject = $mapped_object;
    $this->entity = $mapped_object ? $mapped_object
      ->getMappedEntity() : NULL;
    $this->mapping = $mapped_object ? $mapped_object
      ->getMapping() : NULL;
  }

  /**
   * Getter.
   *
   * @return \Drupal\Core\Entity\FieldableEntityInterface
   *   The entity.
   */
  public function getEntity() {
    return $this->entity;
  }

  /**
   * Getter.
   *
   * @return \Drupal\salesforce_mapping\Entity\SalesforceMappingInterface
   *   The mapping.
   */
  public function getMapping() {
    return $this->mapping;
  }

  /**
   * Getter.
   *
   * @return \Drupal\salesforce_mapping\Entity\MappedObjectInterface
   *   The mapped object.
   */
  public function getMappedObject() {
    return $this->mappedObject;
  }

  /**
   * Returns FALSE if delete is disallowed.
   *
   * Note: a subscriber cannot "force" a delete when any other subscriber has
   * disallowed it.
   *
   * @return false|null
   *   Returns FALSE if DELETE_ALLOWED event has been fired, and any subscriber
   *   wants to prevent delete. Otherwise, returns NULL.
   */
  public function isDeleteAllowed() {
    return $this->deleteAllowed === FALSE ? FALSE : NULL;
  }

  /**
   * Stop Salesforce record from being deleted.
   *
   * @return $this
   */
  public function disallowDelete() {
    $this->deleteAllowed = FALSE;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SalesforceDeleteAllowedEvent::$deleteAllowed protected property Indicates whether delete is allowed to continue.
SalesforceDeleteAllowedEvent::$entity protected property The Drupal entity.
SalesforceDeleteAllowedEvent::$mappedObject protected property The mapped object.
SalesforceDeleteAllowedEvent::disallowDelete public function Stop Salesforce record from being deleted.
SalesforceDeleteAllowedEvent::getEntity public function Getter.
SalesforceDeleteAllowedEvent::getMappedObject public function Getter.
SalesforceDeleteAllowedEvent::getMapping public function Getter.
SalesforceDeleteAllowedEvent::isDeleteAllowed public function Returns FALSE if delete is disallowed.
SalesforceDeleteAllowedEvent::__construct public function SalesforceDeleteAllowedEvent dispatched before deleting an entity.