public function Instances::getOperations in Smart Date 3.4.x
Same name and namespace in other branches
- 8.2 modules/smart_date_recur/src/Controller/Instances.php \Drupal\smart_date_recur\Controller\Instances::getOperations()
- 3.x modules/smart_date_recur/src/Controller/Instances.php \Drupal\smart_date_recur\Controller\Instances::getOperations()
- 3.0.x modules/smart_date_recur/src/Controller/Instances.php \Drupal\smart_date_recur\Controller\Instances::getOperations()
- 3.1.x modules/smart_date_recur/src/Controller/Instances.php \Drupal\smart_date_recur\Controller\Instances::getOperations()
- 3.2.x modules/smart_date_recur/src/Controller/Instances.php \Drupal\smart_date_recur\Controller\Instances::getOperations()
- 3.3.x modules/smart_date_recur/src/Controller/Instances.php \Drupal\smart_date_recur\Controller\Instances::getOperations()
Builds a list of operation links for the entity.
Parameters
array $instance: The entity on which the linked operations will be performed.
Return value
array A not-yet renderable array of operation links.
1 call to Instances::getOperations()
- Instances::buildOperations in modules/
smart_date_recur/ src/ Controller/ Instances.php - Builds a renderable list of operation links for the entity.
File
- modules/
smart_date_recur/ src/ Controller/ Instances.php, line 245
Class
- Instances
- Provides listings of instances (with overrides) for a specified rule.
Namespace
Drupal\smart_date_recur\ControllerCode
public function getOperations(array $instance) {
$operations = [];
// Only one use case doesn't need this, so include by default.
$operations['remove'] = [
'title' => $this
->t('Remove Instance'),
'weight' => 80,
'url' => Url::fromRoute('smart_date_recur.instance.remove', [
'rrule' => $instance['rrule'],
'index' => $instance['rrule_index'],
]),
];
if ($this->useAjax) {
$operations['remove']['url'] = Url::fromRoute('smart_date_recur.instance.remove.ajax', [
'rrule' => $instance['rrule'],
'index' => $instance['rrule_index'],
'confirm' => 0,
]);
$operations['remove']['attributes']['class'][] = 'use-ajax';
}
if (isset($instance['override'])) {
// An override exists, so provide an option to revert (delete) it.
$operations['delete'] = [
'title' => $this
->t('Restore Default'),
'weight' => 100,
'url' => $instance['override']
->toUrl('delete-form'),
];
if ($this->useAjax) {
$operations['delete']['url'] = Url::fromRoute('smart_date_recur.instance.revert.ajax', [
'entity' => $instance['override']
->id(),
'confirm' => 0,
]);
$operations['delete']['attributes']['class'][] = 'use-ajax';
}
switch ($instance['class']) {
case 'cancelled':
// Only option should be to revert.
unset($operations['remove']);
break;
case 'rescheduled':
$operations['edit'] = [
'title' => $this
->t('Reschedule'),
'weight' => 0,
'url' => Url::fromRoute('smart_date_recur.instance.reschedule', [
'rrule' => $instance['rrule'],
'index' => $instance['rrule_index'],
]),
];
if ($this->useAjax) {
$operations['edit']['url'] = Url::fromRoute('smart_date_recur.instance.reschedule.ajax', [
'rrule' => $instance['rrule'],
'index' => $instance['rrule_index'],
]);
$operations['edit']['attributes']['class'][] = 'use-ajax';
}
case 'overriden':
// Removal handled by the delete action already defined.
// TODO: Update the URL of the Edit button above to point to the
// entity form of the referenced entity.
break;
}
}
else {
// Default state, so only options are: create override or cancel.
$operations['create'] = [
'title' => $this
->t('Override'),
'weight' => 10,
'url' => Url::fromRoute('smart_date_recur.instance.reschedule', [
'rrule' => $instance['rrule'],
'index' => $instance['rrule_index'],
]),
];
if ($this->useAjax) {
$operations['create']['url'] = Url::fromRoute('smart_date_recur.instance.reschedule.ajax', [
'rrule' => $instance['rrule'],
'index' => $instance['rrule_index'],
]);
$operations['create']['attributes']['class'][] = 'use-ajax';
}
}
// Sort the operations before returning them.
uasort($operations, '\\Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
return $operations;
}