webCOMAND

cObject::before_approve()

Called right before an object is approved to the repository.  The object's fields will be set to what will be written to the repository, but has not been written yet.

Prototype

mixed before_approve(array $options)

Parameters

  • options - Options that should be passed to parent::approve() if called.

Return

The value that is returned will be passed to after_approve() for use after the object is approved.

Example

<?php
namespace com_example_www\models;

class Contact extends \io_comand_repo\models\Content {
    public function before_approve(array $options): mixed {
        // approve embedded notes, even if they haven't updated
        $notes_to_approve = [];
        foreach($this->Notes as $note) {
            if($note->Update) {
                $notes_to_approve []= $note;
            }
        }
        return [
            'options' => $options,
            'notes_to_approve' => $notes_to_approve,
        ];
    }

    public function after_approve(mixed $data): void {
        // approve embedded notes, even if they haven't updated
        foreach($data['notes_to_approve'] as $note) {
            $note->approve();
        }
    }
}

Related