Results

13.10.2020
contacts_events 8.x-1.x-dev :: modules/printing/src/Controller/TicketPrintingController.php
   * This token needs to be reproducible across different session.
   */
  public function generateRenderAccessToken($type, $id): string {
    // Build the value from our arguments.
    $value = 'cbtp:' . $type;
    if ($id) {
      $value .= ':' . $id;
    }
    $check = $this->generateRenderAccessToken('ticket', $contacts_ticket->id());
    return AccessResult::allowedIf(hash_equals($check, $token));
  }

  /**
   * Access control handler for checking a valid token was supplied.
   */
    $check = $this->generateRenderAccessToken('booking', $commerce_order->id());
    return AccessResult::allowedIf(hash_equals($check, $token));
  }

  /**
   * Access control handler checking if user can download or print their ticket.
   */
  public function printTicket(TicketInterface $contacts_ticket) {
    $ticket_id = $contacts_ticket->id();
    $token = $this->generateRenderAccessToken('ticket', $ticket_id);

    $render_path = Url::fromUserInput('/booking/ticket/' . $ticket_id . '/' . $token . '/render', [
      'absolute' => TRUE,
    ])->toString();

    $return = $this->generateDownload($render_path, DRUPAL_ROOT . '/../tickets/ticket-' . $ticket_id . '.pdf', DRUPAL_ROOT . '/../tickets/print_log');
  public function printBooking(OrderInterface $commerce_order) {
    $order_id = $commerce_order->id();
    $token = $this->generateRenderAccessToken('booking', $order_id);

    $render_path = Url::fromUserInput('/booking/order/' . $order_id . '/' . $token . '/render', [
      'absolute' => TRUE,
    ])->toString();

    $return = $this->generateDownload($render_path, DRUPAL_ROOT . '/../tickets/booking-' . $order_id . '.pdf', DRUPAL_ROOT . '/../tickets/print_log');
19.07.2024
form_field_access 1.0.0-alpha1 :: src/FormFieldAccess.php
  public function elementInfoAlter(array &$info): void {
    foreach ($info as $key => &$value) {
      $value['#pre_render'][] = [FormFieldAccess::class, 'preRenderAccess'];
      if (isset($value['#input']) && $value['#input'] === TRUE) {
        $value['#process'][] = [FormFieldAccess::class, 'processAccess'];
      }
    }
  }
   */
  public static function trustedCallbacks() {
    return ['processAccess', 'preRenderAccess'];
  }

  /**
   * Pre-render method to visually hide sections without fields accessed.
   *
   * @param array $element
   *   Form element.
   */
  public static function preRenderAccess(array $element) {
    if (isset($element['#type'])
      && in_array($element['#type'], ['form', 'container', 'details'])
    ) {
      $child_access = TRUE;

      $children = Element::children($element);
11.11.2022
access_policy 1.0.x-dev :: src/NodeFormAlter.php
          '#type' => 'item',
          '#title' => $this->t('Access'),
          '#markup' => $this->renderAccessPolicyLabels($entity),
          '#wrapper_attributes' => ['class' => ['entity-meta__access container-inline']],
        ];
      }
    }
  }
   *   The access policy labels.
   */
  public function renderAccessPolicyLabels(EntityInterface $entity) {
    $access_policy = $this->storage->getAccessPolicy($entity);
    $labels = array_map(function ($policy) {
      return $policy->label();
    }, $access_policy);

    return implode(', ', $labels);

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc