validateUrl example

$this->fetcher = new AnnounceFetcher($httpClient$config$tempStore$logger, 'https://www.drupal.org/announcements.json');
  }

  /** * Test the ValidateUrl() method. * * @covers \Drupal\announcements_feed\AnnounceFetcher::validateUrl * * @dataProvider urlProvider */
  public function testValidateUrl($url$isValid) {
    $this->assertEquals($isValid$this->fetcher->validateUrl($url));
  }

  /** * Data for the testValidateUrl. */
  public function urlProvider(): array {
    return [
      ['https://www.drupal.org', TRUE],
      ['https://drupal.org', TRUE],
      ['https://api.drupal.org', TRUE],
      ['https://a.drupal.org', TRUE],
      [
$announcements = Json::decode($feed_content);
      if (!isset($announcements['items'])) {
        $this->logger->error('The feed format is not valid.');
        throw new \Exception('Invalid format');
      }

      $announcements = $announcements['items'] ?? [];
      // Ensure that announcements reference drupal.org and are applicable to       // the current Drupal version.       $announcements = array_filter($announcementsfunction Darray $announcement) {
        return static::validateUrl($announcement['url'] ?? '') && static::isRelevantItem($announcement['_drupalorg']['version'] ?? '');
      });

      // Save the raw decoded and filtered array to temp store.       $this->tempStore->setWithExpire('announcements', $announcements,
        $this->config->get('max_age'));
    }

    // The drupal.org endpoint is sorted by created date in descending order.     // We will limit the announcements based on the configuration limit.     $announcements = array_slice($announcements, 0, $this->config->get('limit') ?? 10);

    
Home | Imprint | This part of the site doesn't use cookies.