Пример #1
0
 /**
  * @param \Drupal\block_visibility_groups\Entity\BlockVisibilityGroup $block_visibility_group
  *
  * @return boolean
  */
 public function evaluateGroup(BlockVisibilityGroup $block_visibility_group) {
   $group_id = $block_visibility_group->id();
   if (!isset($this->group_evaluations[$group_id])) {
     /** @var ConditionPluginCollection $conditions */
     $conditions = $block_visibility_group->getConditions();
     if (empty($conditions)) {
       // If no conditions then always true.
       return TRUE;
     }
     $logic = $block_visibility_group->getLogic();
     if ($this->applyContexts($conditions, $logic)) {
       $this->group_evaluations[$group_id] = $this->resolveConditions($conditions, $logic);
     }
     else {
       $this->group_evaluations[$group_id] = FALSE;
     }
   }
   return $this->group_evaluations[$group_id];
 }
  /**
   * @param array $form
   * @param $group
   *
   * @return array
   */
  protected function createHelp(BlockVisibilityGroup $group) {
    $help = '<strong>' . $this->t('Currently viewing') . ': <em>' . $group->label() . '</em></strong>';
    if ($group->getLogic() == 'and') {
      $help .= '<p>' . $this->t('All conditions must pass.') . '</p>';
    }
    else {
      $help .= '<p>' . $this->t('Only one condition must pass.') . '</p>';
    }

    if ($group->isAllowOtherConditions()) {
      $help .= '<p>' . $this->t('Blocks in this group may have other conditions.') . '</p>';
    }
    else {
      $help .= '<p>' . $this->t('Blocks in this group may <strong>not</strong> have other conditions.') . '</p>';
    }

    $help_group = [
      '#type' => 'details',
      '#open' => FALSE,
      '#title' => $this->t('Group Settings'),
      'text' => [
        '#type' => 'markup',
        '#markup' => $help,
      ],
      'edit' => [
        '#type' => 'link',
        '#title' => t('Edit Group Settings'),
        '#url' => $group->urlInfo('edit-form'),
      ],
    ];
    return $help_group;
  }