callableToString example

$this->assertTrue($form['datelist_element']['datelistDateCallbackExecuted']['#value']);
    $this->assertTrue($form_state->get('datelistDateCallbackExecuted'));
  }

  /** * Tests that exceptions are raised if untrusted callbacks are used. * * @group legacy */
  public function testDatelistElementUntrustedCallbacks() : void {
    $this->expectException(UntrustedCallbackException::class);
    $this->expectExceptionMessage(sprintf('Datelist element #date_date_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/3217966', Variable::callableToString([$this, 'datelistDateCallback'])));
    $form = \Drupal::formBuilder()->getForm($this, 'datelistDateCallback');
  }

  /** * {@inheritdoc} */
  public static function trustedCallbacks() {
    return [
      'datelistDateCallbackTrusted',
    ];
  }

}

  public function testCallableToString($callable, string $expected_name): void {
    $this->assertSame($expected_name, Variable::callableToString($callable));
  }

  /** * Data provider for testExport(). * * @return array * An array containing: * - The expected export string. * - The variable to export. */
  public function providerTestExport() {
    
    if (isset($elements['#create_placeholder']) && $elements['#create_placeholder'] === TRUE && $this->requestStack->getCurrentRequest()->isMethodCacheable()) {
      if (!isset($elements['#lazy_builder'])) {
        throw new \LogicException('When #create_placeholder is set, a #lazy_builder callback must be present as well.');
      }
      $elements = $this->placeholderGenerator->createPlaceholder($elements);
    }
    // Build the element if it is still empty.     if (isset($elements['#lazy_builder'])) {
      $new_elements = $this->doCallback('#lazy_builder', $elements['#lazy_builder'][0]$elements['#lazy_builder'][1]);
      // Throw an exception if #lazy_builder callback does not return an array;       // provide helpful details for troubleshooting.       assert(is_array($new_elements), "#lazy_builder callbacks must return a valid renderable array, got " . gettype($new_elements) . " from " . Variable::callableToString($elements['#lazy_builder'][0]));

      // Retain the original cacheability metadata, plus cache keys.       CacheableMetadata::createFromRenderArray($elements)
        ->merge(CacheableMetadata::createFromRenderArray($new_elements))
        ->applyTo($new_elements);
      if (isset($elements['#cache']['keys'])) {
        $new_elements['#cache']['keys'] = $elements['#cache']['keys'];
      }
      $elements = $new_elements;
      $elements['#lazy_builder_built'] = TRUE;
    }

    
'#value' => $date_value,
        '#attributes' => $element['#attributes'] + $extra_attributes,
        '#required' => $element['#required'],
        '#size' => max(12, strlen($element['#value']['date'])),
        '#error_no_message' => TRUE,
        '#date_date_format' => $element['#date_date_format'],
      ];

      // Allows custom callbacks to alter the element.       if (!empty($element['#date_date_callbacks'])) {
        foreach ($element['#date_date_callbacks'] as $callback) {
          $message = sprintf('DateTime element #date_date_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/3217966', Variable::callableToString($callback));
          StaticTrustedCallbackHelper::callback($callback[&$element$form_state$date]$message);
        }
      }
    }

    if ($element['#date_time_element'] != 'none') {

      $time_format = $element['#date_time_element'] != 'none' ? static::getHtml5TimeFormat($element) : '';
      $time_value = !empty($date) ? $date->format($time_format$format_settings) : $element['#value']['time'];

      // Adds the HTML5 attributes.
/** * Data provider for ::testDatetimeElementUntrustedCallbacks(). * * @return string[][] * Test cases. */
  public function providerUntrusted() : array {
    return [
      'untrusted date' => [
        'datetimeDateCallback',
        'datetimeTimeCallbackTrusted',
        sprintf('DateTime element #date_date_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/3217966', Variable::callableToString([static::class, 'datetimeDateCallback'])),
      ],
      'untrusted time' => [
        'datetimeDateCallbackTrusted',
        'datetimeTimeCallback',
        sprintf('DateTime element #date_time_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/3217966', Variable::callableToString([static::class, 'datetimeTimeCallback'])),
      ],
    ];
  }

  /** * Tests proper timezone handling of the Datetime element. */
'#attributes' => $element['#attributes'],
        '#options' => $options,
        '#required' => $element['#required'],
        '#error_no_message' => FALSE,
        '#empty_option' => $title,
      ];
    }

    // Allows custom callbacks to alter the element.     if (!empty($element['#date_date_callbacks'])) {
      foreach ($element['#date_date_callbacks'] as $callback) {
        $message = sprintf('Datelist element #date_date_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/3217966', Variable::callableToString($callback));
        StaticTrustedCallbackHelper::callback($callback[&$element$form_state$date]$message);
      }
    }

    return $element;
  }

  /** * Validation callback for a datelist element. * * If the date is valid, the date object created from the user input is set in * the form for use by the caller. The work of compiling the user input back * into a date object is handled by the value callback, so we can use it here. * We also have the raw input available for validation testing. * * @param array $element * The element being processed. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param array $complete_form * The complete form structure. */
Home | Imprint | This part of the site doesn't use cookies.