You are here

public function ExtendMerciLineItem::execute in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2

Executes the plugin.

Overrides ExecutableInterface::execute

File

modules/merci_line_item/src/Plugin/Action/ExtendMerciLineItem.php, line 77

Class

ExtendMerciLineItem
Promotes a merci_line_item.

Namespace

Drupal\merci_line_item\Plugin\Action

Code

public function execute($entity = NULL) {
  $extend_interval = $this->configuration['extend_interval'];
  $date_field = 'merci_reservation_date';
  $end_date = new DrupalDateTime($entity->{$date_field}
    ->getValue()[0]['end_value'] . ' ' . $extend_interval);
  $end_date_string = $end_date
    ->format(DATETIME_DATETIME_STORAGE_FORMAT);
  $date = $entity->{$date_field}
    ->getValue();
  $date[0]['end_value'] = $end_date_string;
  $entity->{$date_field}
    ->setValue($date);
  $entity
    ->save();
}