Hide actions for disabled quick forms from views
This commit is contained in:
parent
d67e4492d1
commit
1cee2cb2e1
|
@ -7,6 +7,7 @@
|
|||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
|
@ -63,3 +64,42 @@ function farm_quick_farm_entity_bundle_field_info(EntityTypeInterface $entity_ty
|
|||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function farm_quick_form_alter(&$form, FormStateInterface $form_state, $form_id) {
|
||||
|
||||
// Only alter views_form_ forms.
|
||||
if (!str_starts_with($form_id, 'views_form_')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$target = NULL;
|
||||
if (isset($form['header']['asset_bulk_form']['action'])) {
|
||||
$target = 'asset_bulk_form';
|
||||
}
|
||||
if (isset($form['header']['log_bulk_form']['action'])) {
|
||||
$target = 'log_bulk_form';
|
||||
}
|
||||
|
||||
// Alter action options for the target entity type bulk form.
|
||||
if ($target) {
|
||||
|
||||
// Check for disabled quick forms.
|
||||
$disabled_quick_forms = \Drupal::entityTypeManager()->getStorage('quick_form')->getQuery()
|
||||
->accessCheck(TRUE)
|
||||
->condition('status', FALSE)
|
||||
->execute();
|
||||
if (empty($disabled_quick_forms)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove system actions that end with quick_* for a disabled quick form.
|
||||
foreach (array_keys($form['header'][$target]['action']['#options']) as $option_id) {
|
||||
if ((preg_match("/quick_(.*)/", $option_id, $matches)) && in_array($matches[1], $disabled_quick_forms)) {
|
||||
unset($form['header'][$target]['action']['#options'][$option_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue