Commit 7f8dc816 authored by Ariel Barreiro's avatar Ariel Barreiro Committed by Ariel Barreiro
Browse files

Issue #2878824 by hanoii, dknisley, mauro_ptt: Add an invoke hook that allows,...

Issue #2878824 by hanoii, dknisley, mauro_ptt: Add an invoke hook that allows, at first, to prevent a widget from being displayed by external modules
parent d24ee72b
Loading
Loading
Loading
Loading
+11 −0
Changes for src/Widget/WidgetData.php: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -25,6 +25,17 @@ class WidgetData {
   * @return array
   */
  public function output($entity, WidgetInstanceEntity $widget_instance_entity, WidgetEntity $widget_entity, $widget_region = 'content', $field_properties = []) {

    $result = Drupal::moduleHandler()->invokeAll('stacks_pre_output', array(
      $entity,
      $widget_instance_entity,
      $widget_entity,
    ));

    if (!empty($result['skip'])) {
      return [];
    }

    $entity_id = $entity->id();
    $field_exceptions = [];

+20 −0
Changes for stacks.api.php: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -24,3 +24,23 @@ function hook_stacks_output_alter(&$render_array, $entity, $widget_entity) {}
 * 'options', which are the options that are sent to the query builder function.
 */
function hook_widget_node_results_alter(&$query, $group, &$context) {}

/**
 * Allows modules to prevent a specfic widget for being displayed
 *
 * @param Entity $entity: The entity that holds the widget
 * @param WidgetInstanceEntity $widget_instance_entity: The container entity that referecne the widget
 * @param WidgetEntity $widget_instance: The actual widget entity

 * @return array:
 *  'skip': If true, the widget not be displayed
 */
function hook_stacks_pre_output($entity, WidgetInstanceEntity $widget_instance_entity, WidgetEntity $widget_entity) {
  $entity = $args['entity'];

  // Perform some validations.
  $result['skip'] = TRUE;

  return $result;
}