当前位置: 首页>>代码示例>>PHP>>正文


PHP SafeMarkup::format方法代码示例

本文整理汇总了PHP中Drupal\Component\Utility\SafeMarkup::format方法的典型用法代码示例。如果您正苦于以下问题:PHP SafeMarkup::format方法的具体用法?PHP SafeMarkup::format怎么用?PHP SafeMarkup::format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Component\Utility\SafeMarkup的用法示例。


在下文中一共展示了SafeMarkup::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: filter

 /**
  * {@inheritdoc}
  */
 public function filter(RouteCollection $collection, Request $request)
 {
     // Generates a list of Symfony formats matching the acceptable MIME types.
     // @todo replace by proper content negotiation library.
     $acceptable_mime_types = $request->getAcceptableContentTypes();
     $acceptable_formats = array_filter(array_map(array($request, 'getFormat'), $acceptable_mime_types));
     $primary_format = $request->getRequestFormat();
     foreach ($collection as $name => $route) {
         // _format could be a |-delimited list of supported formats.
         $supported_formats = array_filter(explode('|', $route->getRequirement('_format')));
         if (empty($supported_formats)) {
             // No format restriction on the route, so it always matches. Move it to
             // the end of the collection by re-adding it.
             $collection->add($name, $route);
         } elseif (in_array($primary_format, $supported_formats)) {
             // Perfect match, which will get a higher priority by leaving the route
             // on top of the list.
         } elseif (in_array('*/*', $acceptable_mime_types) || array_intersect($acceptable_formats, $supported_formats)) {
             // Move it to the end of the list.
             $collection->add($name, $route);
         } else {
             // Remove the route if it does not match at all.
             $collection->remove($name);
         }
     }
     if (count($collection)) {
         return $collection;
     }
     // We do not throw a
     // \Symfony\Component\Routing\Exception\ResourceNotFoundException here
     // because we don't want to return a 404 status code, but rather a 406.
     throw new NotAcceptableHttpException(SafeMarkup::format('No route found for the specified formats @formats.', array('@formats' => implode(' ', $acceptable_mime_types))));
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:36,代码来源:AcceptHeaderMatcher.php

示例2: testBooleanFormatterSettings

 /**
  * Tests the formatter settings page for the Boolean formatter.
  */
 function testBooleanFormatterSettings()
 {
     // List the options we expect to see on the settings form. Omit the one
     // with the Unicode check/x characters, which does not appear to work
     // well in WebTestBase.
     $options = array('Yes / No', 'True / False', 'On / Off', 'Enabled / Disabled', '1 / 0', 'Custom');
     // Define what the "default" option should look like, depending on the
     // field settings.
     $default = 'Field settings (@on / @off)';
     // For several different values of the field settings, test that the
     // options, including default, are shown correctly.
     $settings = array(array('Yes', 'No'), array('On', 'Off'), array('TRUE', 'FALSE'));
     foreach ($settings as $values) {
         // Set up the field settings.
         $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/fields/node.' . $this->bundle . '.' . $this->fieldName);
         $this->drupalPostForm(NULL, array('settings[on_label]' => $values[0], 'settings[off_label]' => $values[1]), 'Save settings');
         // Open the Manage Display page and trigger the field settings form.
         $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
         $this->drupalPostAjaxForm(NULL, array(), $this->fieldName . '_settings_edit');
         // Test that the settings options are present in the correct format.
         foreach ($options as $string) {
             $this->assertText($string);
         }
         $this->assertText(SafeMarkup::format($default, array('@on' => $values[0], '@off' => $values[1])));
     }
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:29,代码来源:BooleanFormatterSettingsTest.php

示例3: testMatchPath

 /**
  * Test that standard paths works with multiple patterns.
  *
  * @dataProvider getMatchPathData
  */
 public function testMatchPath($patterns, $paths)
 {
     foreach ($paths as $path => $expected_result) {
         $actual_result = $this->pathMatcher->matchPath($path, $patterns);
         $this->assertEquals($actual_result, $expected_result, SafeMarkup::format('Tried matching the path <code>@path</code> to the pattern <pre>@patterns</pre> - expected @expected, got @actual.', array('@path' => $path, '@patterns' => $patterns, '@expected' => var_export($expected_result, TRUE), '@actual' => var_export($actual_result, TRUE))));
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:12,代码来源:PathMatcherTest.php

示例4: createEntity

 /**
  * Creates a new entity
  *
  * @param string $entity_type
  * @param array $values
  *   An array of settings.
  *   Example: 'id' => 'foo'.
  *
  * @return \Drupal\Core\Entity\EntityInterface
  */
 protected function createEntity($entity_type, $values)
 {
     $entity = \Drupal::service('entity_type.manager')->getStorage($entity_type)->create($values);
     $status = $entity->save();
     $this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created %label entity %type.', ['%label' => $entity->getEntityType()->getLabel(), '%type' => $entity->id()]));
     return $entity;
 }
开发者ID:marmouset,项目名称:drupal,代码行数:17,代码来源:OrderTestBase.php

示例5: __construct

 /**
  * Constructs a TargetValidationException object.
  *
  * @param string $message
  *   The un-formatted message.
  * @param array $args
  *   The formatting arguments.
  */
 public function __construct($message = '', array $args = [])
 {
     $this->messageString = $message;
     $this->message = SafeMarkup::format($message, $args);
     $this->args = $args;
     $this->code = 0;
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:15,代码来源:TargetValidationException.php

示例6: testValidateNoMatchingFormats

 /**
  * @covers ::validate
  */
 public function testValidateNoMatchingFormats()
 {
     $this->filterUninstallValidator->expects($this->once())->method('getFilterDefinitionsByProvider')->willReturn(['test_filter_plugin1' => ['id' => 'test_filter_plugin1', 'provider' => 'filter_test'], 'test_filter_plugin2' => ['id' => 'test_filter_plugin2', 'provider' => 'filter_test'], 'test_filter_plugin3' => ['id' => 'test_filter_plugin3', 'provider' => 'filter_test'], 'test_filter_plugin4' => ['id' => 'test_filter_plugin4', 'provider' => 'filter_test']]);
     $filter_plugin_enabled = $this->getMockForAbstractClass('Drupal\\filter\\Plugin\\FilterBase', [['status' => TRUE], '', ['provider' => 'filter_test']]);
     $filter_plugin_disabled = $this->getMockForAbstractClass('Drupal\\filter\\Plugin\\FilterBase', [['status' => FALSE], '', ['provider' => 'filter_test']]);
     // The first format has 2 matching and enabled filters, but the loop breaks
     // after finding the first one.
     $filter_plugin_collection1 = $this->getMockBuilder('Drupal\\filter\\FilterPluginCollection')->disableOriginalConstructor()->getMock();
     $filter_plugin_collection1->expects($this->exactly(3))->method('has')->willReturnMap([['test_filter_plugin1', FALSE], ['test_filter_plugin2', TRUE], ['test_filter_plugin3', TRUE], ['test_filter_plugin4', TRUE]]);
     $filter_plugin_collection1->expects($this->exactly(2))->method('get')->willReturnMap([['test_filter_plugin2', $filter_plugin_disabled], ['test_filter_plugin3', $filter_plugin_enabled], ['test_filter_plugin4', $filter_plugin_enabled]]);
     $filter_format1 = $this->getMock('Drupal\\filter\\FilterFormatInterface');
     $filter_format1->expects($this->once())->method('filters')->willReturn($filter_plugin_collection1);
     $filter_format1->expects($this->once())->method('label')->willReturn('Filter Format 1 Label');
     // The second filter format only has one matching and enabled filter.
     $filter_plugin_collection2 = $this->getMockBuilder('Drupal\\filter\\FilterPluginCollection')->disableOriginalConstructor()->getMock();
     $filter_plugin_collection2->expects($this->exactly(4))->method('has')->willReturnMap([['test_filter_plugin1', FALSE], ['test_filter_plugin2', FALSE], ['test_filter_plugin3', FALSE], ['test_filter_plugin4', TRUE]]);
     $filter_plugin_collection2->expects($this->exactly(1))->method('get')->with('test_filter_plugin4')->willReturn($filter_plugin_enabled);
     $filter_format2 = $this->getMock('Drupal\\filter\\FilterFormatInterface');
     $filter_format2->expects($this->once())->method('filters')->willReturn($filter_plugin_collection2);
     $filter_format2->expects($this->once())->method('label')->willReturn('Filter Format 2 Label');
     $this->filterUninstallValidator->expects($this->once())->method('getEnabledFilterFormats')->willReturn(['test_filter_format1' => $filter_format1, 'test_filter_format2' => $filter_format2]);
     $expected = [SafeMarkup::format('Provides a filter plugin that is in use in the following filter formats: %formats', ['%formats' => implode(', ', ['Filter Format 1 Label', 'Filter Format 2 Label'])])];
     $reasons = $this->filterUninstallValidator->validate($this->randomMachineName());
     $this->assertSame($expected, $reasons);
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:28,代码来源:FilterUninstallValidatorTest.php

示例7: doCreate

 /**
  * {@inheritdoc}
  */
 protected function doCreate(array $values)
 {
     // We have to determine the bundle first.
     $bundle = FALSE;
     if ($this->bundleKey) {
         if (!isset($values[$this->bundleKey])) {
             throw new EntityStorageException(SafeMarkup::format('Missing bundle for entity type @type', array('@type' => $this->entityTypeId)));
         }
         $bundle = $values[$this->bundleKey];
     }
     $entity = new $this->entityClass(array(), $this->entityTypeId, $bundle);
     foreach ($entity as $name => $field) {
         if (isset($values[$name])) {
             $entity->{$name} = $values[$name];
         } elseif (!array_key_exists($name, $values)) {
             $entity->get($name)->applyDefaultValue();
         }
         unset($values[$name]);
     }
     // Set any passed values for non-defined fields also.
     foreach ($values as $name => $value) {
         $entity->{$name} = $value;
     }
     return $entity;
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:28,代码来源:ContentEntityStorageBase.php

示例8: testFetchFields

 /**
  * Tests fetchFields.
  */
 public function testFetchFields()
 {
     $views_data = $this->getMockBuilder('Drupal\\views\\ViewsData')->disableOriginalConstructor()->getMock();
     $views_data->expects($this->once())->method('get')->will($this->returnValue($this->viewsData()));
     $data_helper = new ViewsDataHelper($views_data);
     $expected = array('field' => array('age', 'created', 'job', 'name', 'status'), 'argument' => array('age', 'created', 'id', 'job'), 'filter' => array('created', 'id', 'job', 'name', 'status'), 'sort' => array('age', 'created', 'id', 'name', 'status'), 'area' => array('age', 'created', 'job'), 'header' => array('age', 'created', 'job'), 'footer' => array('age', 'created', 'job'));
     $handler_types = array('field', 'argument', 'filter', 'sort', 'area');
     foreach ($handler_types as $handler_type) {
         $fields = $data_helper->fetchFields('views_test_data', $handler_type);
         $expected_keys = $expected[$handler_type];
         array_walk($expected_keys, function (&$item) {
             $item = "views_test_data.{$item}";
         });
         $this->assertEquals($expected_keys, array_keys($fields), SafeMarkup::format('Handlers of type @handler_type are not listed as expected.', array('@handler_type' => $handler_type)));
     }
     // Check for subtype filtering, so header and footer.
     foreach (array('header', 'footer') as $sub_type) {
         $fields = $data_helper->fetchFields('views_test_data', 'area', FALSE, $sub_type);
         $expected_keys = $expected[$sub_type];
         array_walk($expected_keys, function (&$item) {
             $item = "views_test_data.{$item}";
         });
         $this->assertEquals($expected_keys, array_keys($fields), SafeMarkup::format('Sub_type @sub_type is not filtered as expected.', array('@sub_type' => $sub_type)));
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:28,代码来源:ViewsDataHelperTest.php

示例9: validateArguments

 /**
  * {@inheritdoc}
  */
 protected function validateArguments(array $arguments)
 {
     if (!in_array($arguments['extension'], $this->getToolkit()->getSupportedExtensions())) {
         throw new \InvalidArgumentException(SafeMarkup::format("Invalid extension (@value) specified for the image 'convert' operation", array('@value' => $arguments['extension'])));
     }
     return $arguments;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:10,代码来源:Convert.php

示例10: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     // Create user with content access permission to see if the view is
     // accessible.
     $this->authenticatedUser = $this->drupalCreateUser();
     // Create "Article" and "Basic page" node bundles.
     $this->createNodeBundles();
     try {
         // Install the module and also auto-enable the dependencies.
         $module = 'search_api_db_defaults';
         $dependencies = $this->getModuleDependencies($module);
         $success = $this->container->get('module_installer')->install(array($module), TRUE);
         // Required after enabling a module using the module_installer service.
         $this->rebuildContainer();
         // Assert if the module was successfully enabled.
         $this->assertTrue($success, SafeMarkup::format('Enabled search_api_db_defaults, including its dependencies: %modules', array('%modules' => implode(', ', $dependencies))));
     } catch (UnmetDependenciesException $e) {
         // The exception message has all the details.
         $this->fail($e->getMessage());
     }
     // Rebuild menu so our anonymous user can access the search view.
     $route_builder = $this->container->get('router.builder');
     $route_builder->rebuild();
 }
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:28,代码来源:IntegrationTest.php

示例11: getToolkitOperationPluginId

 /**
  * Returns the plugin ID for a given toolkit and operation.
  *
  * @param \Drupal\Core\ImageToolkit\ImageToolkitInterface $toolkit
  *   The toolkit instance.
  * @param string $operation
  *   The operation (e.g. "crop").
  *
  * @return string
  *   The plugin ID.
  *
  * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
  *   When no plugin is available.
  */
 protected function getToolkitOperationPluginId(ImageToolkitInterface $toolkit, $operation)
 {
     $toolkit_id = $toolkit->getPluginId();
     $definitions = $this->getDefinitions();
     $definitions = array_filter($definitions, function ($definition) use($toolkit_id, $operation) {
         return $definition['toolkit'] == $toolkit_id && $definition['operation'] == $operation;
     });
     if (!$definitions) {
         // If this image toolkit plugin is a derivative and returns no operation,
         // try once again with its base plugin.
         $base_toolkit_id = $toolkit->getBaseId();
         if ($toolkit_id != $base_toolkit_id && !empty($base_toolkit_id)) {
             $base_toolkit = $this->toolkitManager->createInstance($base_toolkit_id);
             return $this->getToolkitOperationPluginId($base_toolkit, $operation);
         }
         $message = SafeMarkup::format("No image operation plugin for '@toolkit' toolkit and '@operation' operation.", array('@toolkit' => $toolkit_id, '@operation' => $operation));
         throw new PluginNotFoundException($toolkit_id . '.' . $operation, $message);
     } else {
         // Pickup the first plugin found.
         // @todo In https://www.drupal.org/node/2110591 we'll return here the UI
         //   selected plugin or the first found if missed.
         $definition = reset($definitions);
         return $definition['id'];
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:39,代码来源:ImageToolkitOperationManager.php

示例12: testMenus

 /**
  * Tests the menu functionality.
  */
 function testMenus()
 {
     $this->drupalPlaceBlock('system_menu_block:main');
     // Create a view with a page display and a menu link in the Main Menu.
     $view = array();
     $view['label'] = $this->randomMachineName(16);
     $view['id'] = strtolower($this->randomMachineName(16));
     $view['description'] = $this->randomMachineName(16);
     $view['page[create]'] = 1;
     $view['page[title]'] = $this->randomMachineName(16);
     $view['page[path]'] = $this->randomMachineName(16);
     $view['page[link]'] = 1;
     $view['page[link_properties][menu_name]'] = 'main';
     $view['page[link_properties][title]'] = $this->randomMachineName(16);
     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
     // Make sure there is a link to the view from the front page (where we
     // expect the main menu to display).
     $this->drupalGet('');
     $this->assertResponse(200);
     $this->assertLink($view['page[link_properties][title]']);
     $this->assertLinkByHref(Url::fromUri('base:' . $view['page[path]'])->toString());
     // Make sure the link is associated with the main menu.
     /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
     $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
     /** @var \Drupal\Core\Menu\MenuLinkInterface $link */
     $link = $menu_link_manager->createInstance('views_view:views.' . $view['id'] . '.page_1');
     $url = $link->getUrlObject();
     $this->assertEqual($url->getRouteName(), 'view.' . $view['id'] . '.page_1', SafeMarkup::format('Found a link to %path in the main menu', array('%path' => $view['page[path]'])));
     $metadata = $link->getMetaData();
     $this->assertEqual(array('view_id' => $view['id'], 'display_id' => 'page_1'), $metadata);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:34,代码来源:MenuTest.php

示例13: addLanguage

 /**
  * Adds a language.
  *
  * @param string $langcode
  *   The language code of the language to add.
  */
 protected function addLanguage($langcode)
 {
     $edit = array('predefined_langcode' => $langcode);
     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
     $this->container->get('language_manager')->reset();
     $this->assertTrue(\Drupal::languageManager()->getLanguage($langcode), SafeMarkup::format('Language %langcode added.', array('%langcode' => $langcode)));
 }
开发者ID:isramv,项目名称:camp-gdl,代码行数:13,代码来源:LocaleUpdateBase.php

示例14: import

 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $file = $row->getSourceProperty($this->configuration['source_path_property']);
     $destination = $row->getDestinationProperty($this->configuration['destination_path_property']);
     $source = $this->configuration['source_base_path'] . $file;
     // Ensure the source file exists, if it's a local URI or path.
     if ($this->isLocalUri($source) && !file_exists($source)) {
         throw new MigrateException(SafeMarkup::format('File @source does not exist.', ['@source' => $source]));
     }
     // If the start and end file is exactly the same, there is nothing to do.
     if ($this->isLocationUnchanged($source, $destination)) {
         return parent::import($row, $old_destination_id_values);
     }
     $replace = $this->getOverwriteMode($row);
     $success = $this->writeFile($source, $destination, $replace);
     if (!$success) {
         $dir = $this->getDirectory($destination);
         if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
             $success = $this->writeFile($source, $destination, $replace);
         } else {
             throw new MigrateException(SafeMarkup::format('Could not create directory @dir', ['@dir' => $dir]));
         }
     }
     if ($success) {
         return parent::import($row, $old_destination_id_values);
     } else {
         throw new MigrateException(SafeMarkup::format('File %source could not be copied to %destination.', ['%source' => $source, '%destination' => $destination]));
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:32,代码来源:EntityFile.php

示例15: submitGetForm

 /**
  * Simulates submission of a form using GET instead of POST.
  *
  * Forms that use the GET method cannot be submitted with
  * WebTestBase::drupalPostForm(), which explicitly uses POST to submit the
  * form. So this method finds the form, verifies that it has input fields and
  * a submit button matching the inputs to this method, and then calls
  * WebTestBase::drupalGet() to simulate the form submission to the 'action'
  * URL of the form (if set, or the current URL if not).
  *
  * See WebTestBase::drupalPostForm() for more detailed documentation of the
  * function parameters.
  *
  * @param string $path
  *   Location of the form to be submitted: either a Drupal path, absolute
  *   path, or NULL to use the current page.
  * @param array $edit
  *   Form field data to submit. Unlike drupalPostForm(), this does not support
  *   file uploads.
  * @param string $submit
  *   Value of the submit button to submit clicking. Unlike drupalPostForm(),
  *   this does not support AJAX.
  * @param string $form_html_id
  *   (optional) HTML ID of the form, to disambiguate.
  */
 protected function submitGetForm($path, $edit, $submit, $form_html_id = NULL)
 {
     if (isset($path)) {
         $this->drupalGet($path);
     }
     if ($this->parse()) {
         // Iterate over forms to find one that matches $edit and $submit.
         $edit_save = $edit;
         $xpath = '//form';
         if (!empty($form_html_id)) {
             $xpath .= "[@id='" . $form_html_id . "']";
         }
         $forms = $this->xpath($xpath);
         foreach ($forms as $form) {
             // Try to set the fields of this form as specified in $edit.
             $edit = $edit_save;
             $post = array();
             $upload = array();
             $submit_matches = $this->handleForm($post, $edit, $upload, $submit, $form);
             if (!$edit && $submit_matches) {
                 // Everything matched, so "submit" the form.
                 $action = isset($form['action']) ? $this->getAbsoluteUrl((string) $form['action']) : NULL;
                 $this->drupalGet($action, array('query' => $post));
                 return;
             }
         }
         // We have not found a form which contained all fields of $edit and
         // the submit button.
         foreach ($edit as $name => $value) {
             $this->fail(SafeMarkup::format('Failed to set field @name to @value', array('@name' => $name, '@value' => $value)));
         }
         $this->assertTrue($submit_matches, format_string('Found the @submit button', array('@submit' => $submit)));
         $this->fail(format_string('Found the requested form fields at @path', array('@path' => $path)));
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:60,代码来源:SearchTestBase.php


注:本文中的Drupal\Component\Utility\SafeMarkup::format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。