You are here

function _cacheflush_cron_entity_form in CacheFlush 8

Implements hook_form_FORM_ID_alter().

2 calls to _cacheflush_cron_entity_form()
cacheflush_cron_form_cacheflush_add_form_alter in modules/cacheflush_cron/cacheflush_cron.module
Implements hook_form_FORM_ID_alter().
cacheflush_cron_form_cacheflush_edit_form_alter in modules/cacheflush_cron/cacheflush_cron.module
Implements hook_form_FORM_ID_alter().

File

modules/cacheflush_cron/cacheflush_cron.module, line 46
Cacheflush cron module.

Code

function _cacheflush_cron_entity_form(&$form, FormStateInterface $form_state, $op) {
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  $cron_job = NULL;
  if ($op == 'edit') {
    $cron_job = CronJob::load('cacheflush_preset_' . $entity
      ->id());
    if ($cron_job) {
      $url = Link::createFromRoute($cron_job, 'entity.ultimate_cron_job.edit_form', [
        'ultimate_cron_job' => 'cacheflush_preset_' . $entity
          ->id(),
      ], [
        'attributes' => [
          'target' => '_blank',
        ],
      ]);
      $url
        ->setText('Edit');
      $renderable = $url
        ->toRenderable();
      $link = render($renderable);
    }
  }
  $form['cron'] = [
    '#type' => "checkbox",
    '#title' => t('Cron'),
    '#weight' => 1,
    '#default_value' => $entity->cron
      ->getValue()[0]['value'] ? 1 : 0,
    '#description' => t('Enable cron job for this preset.') . ($cron_job && isset($link) ? ' ' . $link : NULL),
  ];
}