/** * {@inheritdoc} */ public function getAll($scope = NULL) { if ($scope) { $zones = $this->zoneStorage->loadByProperties(['scope' => $scope]); } else { $zones = $this->zoneStorage->loadMultiple(); } return $zones; }
/** * {@inheritdoc} */ public function getAll($locale = NULL) { if ($locale) { $original_language = $this->languageManager->getConfigOverrideLanguage(); $this->languageManager->setConfigOverrideLanguage(new Language(['id' => $locale])); $address_formats = $this->formatStorage->loadMultiple(); $this->languageManager->setConfigOverrideLanguage($original_language); } else { $address_formats = $this->formatStorage->loadMultiple(); } return $address_formats; }
/** * {@inheritdoc} */ public function importTranslations(array $langcodes) { $available_translations = $this->getAvailableTranslations(); $available_translations = array_intersect_key($available_translations, array_flip($langcodes)); foreach ($available_translations as $langcode => $country_codes) { $address_formats = $this->storage->loadMultiple($country_codes); foreach ($address_formats as $country_code => $address_format) { $external_translation = $this->externalRepository->get($country_code, $langcode); $config_name = $address_format->getConfigDependencyName(); $config_translation = $this->languageManager->getLanguageConfigOverride($langcode, $config_name); $config_translation->set('format', $external_translation->getFormat()); $config_translation->save(); } } }
/** * Tests overriding an existing route. * * @covers ::alterRoutes * @covers ::findPageRouteName * * @dataProvider providerTestAlterRoutesOverrideExisting */ public function testAlterRoutesOverrideExisting($page_path, $existing_route_path, $requirements = []) { $route_name = 'test_route'; // Set up a page with the same path as an existing route. $page = $this->prophesize(PageInterface::class); $page->status()->willReturn(TRUE)->shouldBeCalled(); $page->getPath()->willReturn($page_path)->shouldBeCalled(); $variant1 = $this->prophesize(PageVariantInterface::class); $variant1->getWeight()->willReturn(0); $page->getVariants()->willReturn(['variant1' => $variant1->reveal()]); $page->id()->willReturn('page1'); $page->label()->willReturn(NULL); $page->usesAdminTheme()->willReturn(FALSE); $this->pageStorage->loadMultiple()->willReturn(['page1' => $page->reveal()])->shouldBeCalledTimes(1); $this->cacheTagsInvalidator->invalidateTags(["page_manager_route_name:{$route_name}"])->shouldBeCalledTimes(1); $collection = new RouteCollection(); $collection->add($route_name, new Route($existing_route_path, ['default_exists' => 'default_value'], $requirements, ['parameters' => ['foo' => 'bar']])); $route_event = new RouteBuildEvent($collection); $this->routeSubscriber->onAlterRoutes($route_event); // The normal route name is not used, the existing route name is instead. $this->assertSame(1, $collection->count()); $this->assertNull($collection->get('page_manager.page_view_page1')); $this->assertNull($collection->get('page_manager.page_view_page1_variant1')); $route = $collection->get($route_name); $expected_defaults = ['_entity_view' => 'page_manager_page_variant', '_title' => NULL, 'page_manager_page_variant' => 'variant1', 'page_manager_page' => 'page1', 'page_manager_page_variant_weight' => 0, 'base_route_name' => $route_name]; $expected_requirements = $requirements; $expected_options = ['compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler', 'parameters' => ['page_manager_page_variant' => ['type' => 'entity:page_variant'], 'page_manager_page' => ['type' => 'entity:page'], 'foo' => 'bar'], '_admin_route' => FALSE]; $this->assertMatchingRoute($route, $existing_route_path, $expected_defaults, $expected_requirements, $expected_options); }
/** * Tests overriding an existing route with configured parameters. * * @covers ::alterRoutes * @covers ::findPageRouteName * * @dataProvider providerTestAlterRoutesOverrideExisting */ public function testAlterRoutesOverrideExistingWithConfiguredParameters($page_path, $existing_route_path, $requirements = []) { $route_name = 'test_route'; // Set up a page with the same path as an existing route. /** @var \Drupal\page_manager\PageInterface|\Prophecy\Prophecy\ProphecyInterface $page */ $page = $this->prophesize(PageInterface::class); $page->status()->willReturn(TRUE); $page->getPath()->willReturn($page_path); $page->id()->willReturn('page1'); $page->label()->willReturn(NULL); $page->usesAdminTheme()->willReturn(FALSE); $page->getParameters()->willReturn(['foo' => ['machine_name' => 'foo', 'type' => 'integer', 'label' => 'Foo'], 'test_route' => ['machine_name' => 'test_route', 'type' => '', 'label' => '']]); $variant1 = $this->prophesize(PageVariantInterface::class); $variant1->getWeight()->willReturn(0); $page->getVariants()->willReturn(['variant1' => $variant1->reveal()]); $this->pageStorage->loadMultiple()->willReturn(['page1' => $page->reveal()]); $collection = new RouteCollection(); $collection->add($route_name, new Route($existing_route_path, ['default_exists' => 'default_value'], $requirements, ['parameters' => ['foo' => ['bar' => 'bar']]])); $route_event = new RouteBuildEvent($collection); $this->routeSubscriber->onAlterRoutes($route_event); $expected_defaults = ['_entity_view' => 'page_manager_page_variant', '_title' => NULL, 'page_manager_page_variant' => 'variant1', 'page_manager_page' => 'page1', 'page_manager_page_variant_weight' => 0, 'base_route_name' => $route_name]; $expected_requirements = $requirements + ['_page_access' => 'page_manager_page.view']; $expected_options = ['compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler', 'parameters' => ['foo' => ['bar' => 'bar', 'type' => 'integer'], 'page_manager_page_variant' => ['type' => 'entity:page_variant'], 'page_manager_page' => ['type' => 'entity:page']], '_admin_route' => FALSE]; $this->assertMatchingRoute($collection->get($route_name), $existing_route_path, $expected_defaults, $expected_requirements, $expected_options); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); // The machine name field should already check to see if the requested // machine name is available. $pattern = trim($form_state->getValue('date_format_pattern')); foreach ($this->dateFormatStorage->loadMultiple() as $format) { if ($format->getPattern() == $pattern && $format->id() == $this->entity->id()) { drupal_set_message(t('The existing format/name combination has not been altered.')); continue; } } }
/** * {@inheritdoc} */ public function validate(array $form, FormStateInterface $form_state) { parent::validate($form, $form_state); // The machine name field should already check to see if the requested // machine name is available. Regardless of machine_name or human readable // name, check to see if the provided pattern exists. $pattern = trim($form_state->getValue('date_format_pattern')); foreach ($this->dateFormatStorage->loadMultiple() as $format) { if ($format->getPattern() == $pattern && ($this->entity->isNew() || $format->id() != $this->entity->id())) { $form_state->setErrorByName('date_format_pattern', $this->t('This format already exists. Enter a unique format string.')); continue; } } }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $options = []; foreach ($this->typeStorage->loadMultiple() as $type) { $options[$type->id()] = $type->label(); } $form['crop_type'] = [ '#type' => 'select', '#title' => t('Crop type'), '#default_value' => $this->configuration['crop_type'], '#options' => $options, '#description' => t('Crop type to be used for the image style.'), ]; return $form; }
/** * Tests overriding an existing route. * * @covers ::alterRoutes */ public function testAlterRoutesOverrideExisting() { // Set up a page with the same path as an existing route. $page = $this->prophesize(PageInterface::class); $page->status()->willReturn(TRUE)->shouldBeCalledTimes(1); $page->getPath()->willReturn('/test_route')->shouldBeCalledTimes(1); $page->isFallbackPage()->willReturn(FALSE); $page->label()->willReturn(NULL); $page->usesAdminTheme()->willReturn(FALSE); $this->pageStorage->loadMultiple()->willReturn(['page1' => $page->reveal()])->shouldBeCalledTimes(1); $collection = new RouteCollection(); $collection->add('test_route', new Route('test_route', [], [], ['parameters' => ['foo' => 'bar']])); $route_event = new RouteBuildEvent($collection); $this->routeSubscriber->onAlterRoutes($route_event); // The normal route name is not used, the existing route name is instead. $this->assertSame(1, $collection->count()); $this->assertNull($collection->get('page_manager.page_view_page1')); $route = $collection->get('test_route'); $expected_defaults = ['_entity_view' => 'page_manager_page', 'page_manager_page' => 'page1', '_title' => NULL]; $expected_requirements = ['_entity_access' => 'page_manager_page.view']; $expected_options = ['compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler', 'parameters' => ['page_manager_page' => ['type' => 'entity:page'], 'foo' => 'bar'], '_admin_route' => FALSE]; $this->assertMatchingRoute($route, '/test_route', $expected_defaults, $expected_requirements, $expected_options); }