• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP file_url_transform_relative函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中file_url_transform_relative函数的典型用法代码示例。如果您正苦于以下问题:PHP file_url_transform_relative函数的具体用法?PHP file_url_transform_relative怎么用?PHP file_url_transform_relative使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: doTestAutoOrientOperations

 /**
  * Auto Orientation operations test.
  */
 public function doTestAutoOrientOperations()
 {
     $image_factory = $this->container->get('image.factory');
     $test_data = [['test_file' => drupal_get_path('module', 'image_effects') . '/misc/portrait-painting.jpg', 'original_width' => 640, 'original_height' => 480, 'derivative_width' => 200, 'derivative_height' => 267], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-test.jpg', 'original_width' => 40, 'original_height' => 20, 'derivative_width' => 200, 'derivative_height' => 100], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-1.png', 'original_width' => 360, 'original_height' => 240, 'derivative_width' => 200, 'derivative_height' => 133]];
     foreach ($test_data as $data) {
         // Get expected URIs.
         $original_uri = file_unmanaged_copy($data['test_file'], 'public://', FILE_EXISTS_RENAME);
         $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri);
         // Test source image dimensions.
         $image = $image_factory->get($original_uri);
         $this->assertEqual($data['original_width'], $image->getWidth());
         $this->assertEqual($data['original_height'], $image->getHeight());
         // Load Image Style and get expected derivative URL.
         $image_style = ImageStyle::load('image_effects_test');
         $url = file_url_transform_relative($image_style->buildUrl($original_uri));
         // Check that ::transformDimensions returns expected dimensions.
         $variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight());
         $this->assertEqual('<img src="' . $url . '" width="' . $data['derivative_width'] . '" height="' . $data['derivative_height'] . '" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables));
         // Check that ::applyEffect generates image with expected dimensions.
         $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
         $image = $image_factory->get($generated_uri);
         $this->assertEqual($data['derivative_width'], $image->getWidth());
         $this->assertEqual($data['derivative_height'], $image->getHeight());
     }
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:28,代码来源:ImageEffectsAutoOrientTest.php


示例2: testPictureOnNodeComment

 /**
  * Tests embedded users on node pages.
  */
 function testPictureOnNodeComment()
 {
     $this->drupalLogin($this->webUser);
     // Save a new picture.
     $image = current($this->drupalGetTestFiles('image'));
     $file = $this->saveUserPicture($image);
     $node = $this->drupalCreateNode(array('type' => 'article'));
     // Enable user pictures on nodes.
     $this->config('system.theme.global')->set('features.node_user_picture', TRUE)->save();
     $image_style_id = $this->config('core.entity_view_display.user.user.compact')->get('content.user_picture.settings.image_style');
     $style = ImageStyle::load($image_style_id);
     $image_url = file_url_transform_relative($style->buildUrl($file->getfileUri()));
     $alt_text = 'Profile picture for user ' . $this->webUser->getUsername();
     // Verify that the image is displayed on the node page.
     $this->drupalGet('node/' . $node->id());
     $elements = $this->cssSelect('.node__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]');
     $this->assertEqual(count($elements), 1, 'User picture with alt text found on node page.');
     // Enable user pictures on comments, instead of nodes.
     $this->config('system.theme.global')->set('features.node_user_picture', FALSE)->set('features.comment_user_picture', TRUE)->save();
     $edit = array('comment_body[0][value]' => $this->randomString());
     $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Save'));
     $elements = $this->cssSelect('.comment__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]');
     $this->assertEqual(count($elements), 1, 'User picture with alt text found on the comment.');
     // Disable user pictures on comments and nodes.
     $this->config('system.theme.global')->set('features.node_user_picture', FALSE)->set('features.comment_user_picture', FALSE)->save();
     $this->drupalGet('node/' . $node->id());
     $this->assertNoRaw(file_uri_target($file->getFileUri()), 'User picture not found on node and comment.');
 }
开发者ID:Wylbur,项目名称:gj,代码行数:31,代码来源:UserPictureTest.php


示例3: process

 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $result = new FilterProcessResult($text);
     if (stristr($text, 'data-entity-type="file"') !== FALSE) {
         $dom = Html::load($text);
         $xpath = new \DOMXPath($dom);
         $processed_uuids = array();
         foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) {
             $uuid = $node->getAttribute('data-entity-uuid');
             // If there is a 'src' attribute, set it to the file entity's current
             // URL. This ensures the URL works even after the file location changes.
             if ($node->hasAttribute('src')) {
                 $file = $this->entityManager->loadEntityByUuid('file', $uuid);
                 if ($file) {
                     $node->setAttribute('src', file_url_transform_relative(file_create_url($file->getFileUri())));
                 }
             }
             // Only process the first occurrence of each file UUID.
             if (!isset($processed_uuids[$uuid])) {
                 $processed_uuids[$uuid] = TRUE;
                 $file = $this->entityManager->loadEntityByUuid('file', $uuid);
                 if ($file) {
                     $result->addCacheTags($file->getCacheTags());
                 }
             }
         }
         $result->setProcessedText(Html::serialize($dom));
     }
     return $result;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:33,代码来源:EditorFileReference.php


示例4: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $elements = array();
     foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
         $elements[$delta] = array('#markup' => file_url_transform_relative(file_create_url($file->getFileUri())), '#cache' => array('tags' => $file->getCacheTags()));
     }
     return $elements;
 }
开发者ID:Wylbur,项目名称:gj,代码行数:11,代码来源:UrlPlainFormatter.php


示例5: testThemeImageWithSrcsetWidth

 /**
  * Tests that an image with the srcset and widths is output correctly.
  */
 function testThemeImageWithSrcsetWidth()
 {
     // Test with multipliers.
     $widths = array(rand(0, 500) . 'w', rand(500, 1000) . 'w');
     $image = array('#theme' => 'image', '#srcset' => array(array('uri' => $this->testImages[0], 'width' => $widths[0]), array('uri' => $this->testImages[1], 'width' => $widths[1])), '#width' => rand(0, 1000) . 'px', '#height' => rand(0, 500) . 'px', '#alt' => $this->randomMachineName(), '#title' => $this->randomMachineName());
     $this->render($image);
     // Make sure the srcset attribute has the correct value.
     $this->assertRaw(file_url_transform_relative(file_create_url($this->testImages[0])) . ' ' . $widths[0] . ', ' . file_url_transform_relative(file_create_url($this->testImages[1])) . ' ' . $widths[1], 'Correct output for image with srcset attribute and width descriptors.');
 }
开发者ID:318io,项目名称:318-io,代码行数:12,代码来源:ImageTest.php


示例6: doTestSetCanvasOperations

 /**
  * Set canvas operations test.
  */
 public function doTestSetCanvasOperations()
 {
     $image_factory = $this->container->get('image.factory');
     $test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png';
     $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME);
     $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri);
     // Test EXACT size canvas.
     $effect = ['id' => 'image_effects_set_canvas', 'data' => ['canvas_size' => 'exact', 'canvas_color][container][transparent' => FALSE, 'canvas_color][container][hex' => '#FF00FF', 'canvas_color][container][opacity' => 100, 'exact][width' => '200%', 'exact][height' => '200%']];
     $uuid = $this->addEffectToTestStyle($effect);
     // Load Image Style.
     $image_style = ImageStyle::load('image_effects_test');
     // Check that ::transformDimensions returns expected dimensions.
     $image = $image_factory->get($original_uri);
     $this->assertEqual(40, $image->getWidth());
     $this->assertEqual(20, $image->getHeight());
     $url = file_url_transform_relative($image_style->buildUrl($original_uri));
     $variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight());
     $this->assertEqual('<img src="' . $url . '" width="80" height="40" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables));
     // Check that ::applyEffect generates image with expected canvas.
     $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
     $image = $image_factory->get($generated_uri, 'gd');
     $this->assertEqual(80, $image->getWidth());
     $this->assertEqual(40, $image->getHeight());
     $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 0, 0)));
     $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 79, 0)));
     $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 0, 39)));
     $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 79, 39)));
     // Remove effect.
     $this->removeEffectFromTestStyle($uuid);
     // Test RELATIVE size canvas.
     $effect = ['id' => 'image_effects_set_canvas', 'data' => ['canvas_size' => 'relative', 'canvas_color][container][transparent' => FALSE, 'canvas_color][container][hex' => '#FFFF00', 'canvas_color][container][opacity' => 100, 'relative][right' => 10, 'relative][left' => 20, 'relative][top' => 30, 'relative][bottom' => 40]];
     $uuid = $this->addEffectToTestStyle($effect);
     // Load Image Style.
     $image_style = ImageStyle::load('image_effects_test');
     // Check that ::transformDimensions returns expected dimensions.
     $image = $image_factory->get($original_uri);
     $this->assertEqual(40, $image->getWidth());
     $this->assertEqual(20, $image->getHeight());
     $url = file_url_transform_relative($image_style->buildUrl($original_uri));
     $variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight());
     $this->assertEqual('<img src="' . $url . '" width="70" height="90" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables));
     // Check that ::applyEffect generates image with expected canvas.
     $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
     $image = $image_factory->get($generated_uri, 'gd');
     $this->assertEqual(70, $image->getWidth());
     $this->assertEqual(90, $image->getHeight());
     $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 0, 0)));
     $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 69, 0)));
     $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 0, 89)));
     $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 69, 89)));
     // Remove effect.
     $this->removeEffectFromTestStyle($uuid);
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:56,代码来源:ImageEffectsSetCanvasTest.php


示例7: testUrlHandling

 /**
  * Tests relative, root-relative, protocol-relative and absolute URLs.
  */
 public function testUrlHandling()
 {
     // Only the plain_text text format is available by default, which escapes
     // all HTML.
     FilterFormat::create(['format' => 'full_html', 'name' => 'Full HTML', 'filters' => []])->save();
     $defaults = ['type' => 'article', 'promote' => 1];
     $this->drupalCreateNode($defaults + ['body' => ['value' => '<p><a href="' . file_url_transform_relative(file_create_url('public://root-relative')) . '">Root-relative URL</a></p>', 'format' => 'full_html']]);
     $protocol_relative_url = substr(file_create_url('public://protocol-relative'), strlen(\Drupal::request()->getScheme() . ':'));
     $this->drupalCreateNode($defaults + ['body' => ['value' => '<p><a href="' . $protocol_relative_url . '">Protocol-relative URL</a></p>', 'format' => 'full_html']]);
     $absolute_url = file_create_url('public://absolute');
     $this->drupalCreateNode($defaults + ['body' => ['value' => '<p><a href="' . $absolute_url . '">Absolute URL</a></p>', 'format' => 'full_html']]);
     $this->drupalGet('rss.xml');
     $this->assertRaw(file_create_url('public://root-relative'), 'Root-relative URL is transformed to absolute.');
     $this->assertRaw($protocol_relative_url, 'Protocol-relative URL is left untouched.');
     $this->assertRaw($absolute_url, 'Absolute URL is left untouched.');
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:19,代码来源:NodeRSSContentTest.php


示例8: testImageButtonDisplay

 /**
  * Method tests CKEditor image buttons.
  */
 public function testImageButtonDisplay()
 {
     $this->drupalLogin($this->admin_user);
     // Install the Arabic language (which is RTL) and configure as the default.
     $edit = [];
     $edit['predefined_langcode'] = 'ar';
     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
     $edit = ['site_default_language' => 'ar'];
     $this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
     // Once the default language is changed, go to the tested text format
     // configuration page.
     $this->drupalGet('admin/config/content/formats/manage/full_html');
     // Check if any image button is loaded in CKEditor json.
     $json_encode = function ($html) {
         return trim(Json::encode($html), '"');
     };
     $markup = $json_encode(file_url_transform_relative(file_create_url('core/modules/ckeditor/js/plugins/drupalimage/image.png')));
     $this->assertRaw($markup);
 }
开发者ID:Wylbur,项目名称:gj,代码行数:22,代码来源:CKEditorToolbarButtonTest.php


示例9: preRenderButton

 /**
  * {@inheritdoc}
  */
 public static function preRenderButton($element)
 {
     $element['#attributes']['type'] = 'image';
     Element::setAttributes($element, array('id', 'name', 'value'));
     $element['#attributes']['src'] = file_url_transform_relative(file_create_url($element['#src']));
     if (!empty($element['#title'])) {
         $element['#attributes']['alt'] = $element['#title'];
         $element['#attributes']['title'] = $element['#title'];
     }
     $element['#attributes']['class'][] = 'image-button';
     if (!empty($element['#button_type'])) {
         $element['#attributes']['class'][] = 'image-button--' . $element['#button_type'];
     }
     $element['#attributes']['class'][] = 'js-form-submit';
     $element['#attributes']['class'][] = 'form-submit';
     if (!empty($element['#attributes']['disabled'])) {
         $element['#attributes']['class'][] = 'is-disabled';
     }
     return $element;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:23,代码来源:ImageButton.php


示例10: testFile

 /**
  * Test the field formatter with a file field and file upload widget.
  */
 public function testFile()
 {
     // Create a test node with an image file.
     $this->createNodeWithFile();
     $node = $this->node;
     $xml_path = 'juicebox/xml/field/node/' . $node->id() . '/' . $this->instFieldName . '/full';
     $xml_url = \Drupal::url('juicebox.xml_field', array('entityType' => 'node', 'entityId' => $node->id(), 'fieldName' => $this->instFieldName, 'displayName' => 'full'));
     // Get the urls to the test image and thumb derivative used by default.
     $uri = \Drupal\file\Entity\File::load($node->{$this->instFieldName}[0]->target_id)->getFileUri();
     $test_image_url = entity_load('image_style', 'juicebox_medium')->buildUrl($uri);
     $test_thumb_url = entity_load('image_style', 'juicebox_square_thumb')->buildUrl($uri);
     // Check for correct embed markup as anon user.
     $this->drupalLogout();
     $this->drupalGet('node/' . $node->id());
     $this->assertRaw(trim(json_encode(array('configUrl' => $xml_url)), '{}"'), 'Gallery setting found in Drupal.settings.');
     $this->assertRaw('id="node--' . $node->id() . '--' . str_replace('_', '-', $this->instFieldName) . '--full"', 'Embed code wrapper found.');
     $this->assertRaw(Html::escape(file_url_transform_relative($test_image_url)), 'Test image found in embed code');
     // Check for correct XML.
     $this->drupalGet($xml_path);
     $this->assertRaw('<?xml version="1.0" encoding="UTF-8"?>', 'Valid XML detected.');
     $this->assertRaw('imageURL="' . Html::escape($test_image_url), 'Test image found in XML.');
     $this->assertRaw('thumbURL="' . Html::escape($test_thumb_url), 'Test thumbnail found in XML.');
     $this->assertRaw('<juicebox gallerywidth="100%" galleryheight="100%" backgroundcolor="#222222" textcolor="rgba(255,255,255,1)" thumbframecolor="rgba(255,255,255,.5)" showopenbutton="TRUE" showexpandbutton="TRUE" showthumbsbutton="TRUE" usethumbdots="FALSE" usefullscreenexpand="FALSE">', 'Expected default configuration options set in XML.');
 }
开发者ID:pulibrary,项目名称:recap,代码行数:27,代码来源:JuiceboxFileCase.php


示例11: processUserConf

 /**
  * Processes raw profile configuration of a user.
  */
 public static function processUserConf(array $conf, AccountProxyInterface $user)
 {
     // Convert MB to bytes
     $conf['maxsize'] *= 1048576;
     $conf['quota'] *= 1048576;
     // Set root uri and url
     $conf['root_uri'] = $conf['scheme'] . '://';
     // file_create_url requires a filepath for some schemes like private://
     $conf['root_url'] = preg_replace('@/(?:%2E|\\.)$@i', '', file_create_url($conf['root_uri'] . '.'));
     // Convert to relative
     if (!\Drupal::config('imce.settings')->get('abs_urls')) {
         $conf['root_url'] = file_url_transform_relative($conf['root_url']);
     }
     $conf['token'] = $user->isAnonymous() ? 'anon' : \Drupal::csrfToken()->get('imce');
     // Process folders
     $conf['folders'] = static::processUserFolders($conf['folders'], $user);
     // Call plugin processors
     \Drupal::service('plugin.manager.imce.plugin')->processUserConf($conf, $user);
     return $conf;
 }
开发者ID:aakb,项目名称:cfia,代码行数:23,代码来源:Imce.php


示例12: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $response = new AjaxResponse();
     // Convert any uploaded files from the FID values to data-editor-file-uuid
     // attributes.
     if (!empty($form_state['values']['fid'][0])) {
         $file = file_load($form_state['values']['fid'][0]);
         $file_url = file_create_url($file->getFileUri());
         // Transform absolute image URLs to relative image URLs: prevent problems
         // on multisite set-ups and prevent mixed content errors.
         $file_url = file_url_transform_relative($file_url);
         $form_state['values']['attributes']['src'] = $file_url;
         $form_state['values']['attributes']['data-editor-file-uuid'] = $file->uuid();
     }
     if (form_get_errors($form_state)) {
         unset($form['#prefix'], $form['#suffix']);
         $status_messages = array('#theme' => 'status_messages');
         $output = drupal_render($form);
         $output = '<div>' . drupal_render($status_messages) . $output . '</div>';
         $response->addCommand(new HtmlCommand('#editor-image-dialog-form', $output));
     } else {
         $response->addCommand(new EditorDialogSave($form_state['values']));
         $response->addCommand(new CloseModalDialogCommand());
     }
     return $response;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:29,代码来源:EditorImageDialog.php


示例13: testImageStyleTheme

 /**
  * Tests usage of the image style theme function.
  */
 function testImageStyleTheme()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     // Create an image.
     $files = $this->drupalGetTestFiles('image');
     $file = reset($files);
     $original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
     // Create a style.
     $style = ImageStyle::create(array('name' => 'image_test', 'label' => 'Test'));
     $style->save();
     $url = file_url_transform_relative($style->buildUrl($original_uri));
     // Create the base element that we'll use in the tests below.
     $base_element = array('#theme' => 'image_style', '#style_name' => 'image_test', '#uri' => $original_uri);
     $element = $base_element;
     $this->setRawContent($renderer->renderRoot($element));
     $elements = $this->xpath('//img[@class="image-style-image-test" and @src=:url and @alt=""]', array(':url' => $url));
     $this->assertEqual(count($elements), 1, 'theme_image_style() renders an image correctly.');
     // Test using theme_image_style() with a NULL value for the alt option.
     $element = $base_element;
     $element['#alt'] = NULL;
     $this->setRawContent($renderer->renderRoot($element));
     $elements = $this->xpath('//img[@class="image-style-image-test" and @src=:url]', array(':url' => $url));
     $this->assertEqual(count($elements), 1, 'theme_image_style() renders an image correctly with a NULL value for the alt option.');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:ImageThemeFunctionTest.php


示例14: getDefaultContentsCssConfig

 protected function getDefaultContentsCssConfig()
 {
     return array(file_url_transform_relative(file_create_url('core/modules/ckeditor/css/ckeditor-iframe.css')), file_url_transform_relative(file_create_url('core/modules/system/css/components/align.module.css')));
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:4,代码来源:CKEditorTest.php


示例15: _testColor

 /**
  * Tests the Color module functionality using the given theme.
  *
  * @param string $theme
  *   The machine name of the theme being tested.
  * @param array $test_values
  *   An associative array of test settings (i.e. 'Main background', 'Text
  *   color', 'Color set', etc) for the theme which being tested.
  */
 function _testColor($theme, $test_values)
 {
     $this->config('system.theme')->set('default', $theme)->save();
     $settings_path = 'admin/appearance/settings/' . $theme;
     $this->drupalLogin($this->bigUser);
     $this->drupalGet($settings_path);
     $this->assertResponse(200);
     $this->assertUniqueText('Color set');
     $edit['scheme'] = '';
     $edit[$test_values['palette_input']] = '#123456';
     $this->drupalPostForm($settings_path, $edit, t('Save configuration'));
     $this->drupalGet('<front>');
     $stylesheets = $this->config('color.theme.' . $theme)->get('stylesheets');
     foreach ($stylesheets as $stylesheet) {
         $this->assertPattern('|' . file_url_transform_relative(file_create_url($stylesheet)) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')');
         $stylesheet_content = join("\n", file($stylesheet));
         $this->assertTrue(strpos($stylesheet_content, 'color: #123456') !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
     }
     $this->drupalGet($settings_path);
     $this->assertResponse(200);
     $edit['scheme'] = $test_values['scheme'];
     $this->drupalPostForm($settings_path, $edit, t('Save configuration'));
     $this->drupalGet('<front>');
     $stylesheets = $this->config('color.theme.' . $theme)->get('stylesheets');
     foreach ($stylesheets as $stylesheet) {
         $stylesheet_content = join("\n", file($stylesheet));
         $this->assertTrue(strpos($stylesheet_content, 'color: ' . $test_values['scheme_color']) !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
     }
     // Test with aggregated CSS turned on.
     $config = $this->config('system.performance');
     $config->set('css.preprocess', 1);
     $config->save();
     $this->drupalGet('<front>');
     $stylesheets = \Drupal::state()->get('drupal_css_cache_files') ?: array();
     $stylesheet_content = '';
     foreach ($stylesheets as $uri) {
         $stylesheet_content .= join("\n", file(drupal_realpath($uri)));
     }
     $this->assertTrue(strpos($stylesheet_content, 'public://') === FALSE, 'Make sure the color paths have been translated to local paths. (' . $theme . ')');
     $config->set('css.preprocess', 0);
     $config->save();
 }
开发者ID:318io,项目名称:318-io,代码行数:51,代码来源:ColorTest.php


示例16: testImageFieldSettings

 /**
  * Tests for image field settings.
  */
 function testImageFieldSettings()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
     $test_image = current($this->drupalGetTestFiles('image'));
     list(, $test_image_extension) = explode('.', $test_image->filename);
     $field_name = strtolower($this->randomMachineName());
     $field_settings = array('alt_field' => 1, 'file_extensions' => $test_image_extension, 'max_filesize' => '50 KB', 'max_resolution' => '100x100', 'min_resolution' => '10x10', 'title_field' => 1);
     $widget_settings = array('preview_image_style' => 'medium');
     $field = $this->createImageField($field_name, 'article', array(), $field_settings, $widget_settings);
     // Verify that the min/max resolution set on the field are properly
     // extracted, and displayed, on the image field's configuration form.
     $this->drupalGet('admin/structure/types/manage/article/fields/' . $field->id());
     $this->assertFieldByName('settings[max_resolution][x]', '100', 'Expected max resolution X value of 100.');
     $this->assertFieldByName('settings[max_resolution][y]', '100', 'Expected max resolution Y value of 100.');
     $this->assertFieldByName('settings[min_resolution][x]', '10', 'Expected min resolution X value of 10.');
     $this->assertFieldByName('settings[min_resolution][y]', '10', 'Expected min resolution Y value of 10.');
     $this->drupalGet('node/add/article');
     $this->assertText(t('50 KB limit.'), 'Image widget max file size is displayed on article form.');
     $this->assertText(t('Allowed types: @extensions.', array('@extensions' => $test_image_extension)), 'Image widget allowed file types displayed on article form.');
     $this->assertText(t('Images must be larger than 10x10 pixels. Images larger than 100x100 pixels will be resized.'), 'Image widget allowed resolution displayed on article form.');
     // We have to create the article first and then edit it because the alt
     // and title fields do not display until the image has been attached.
     // Create alt text for the image.
     $alt = $this->randomMachineName();
     $nid = $this->uploadNodeImage($test_image, $field_name, 'article', $alt);
     $this->drupalGet('node/' . $nid . '/edit');
     $this->assertFieldByName($field_name . '[0][alt]', '', 'Alt field displayed on article form.');
     $this->assertFieldByName($field_name . '[0][title]', '', 'Title field displayed on article form.');
     // Verify that the attached image is being previewed using the 'medium'
     // style.
     $node_storage->resetCache(array($nid));
     $node = $node_storage->load($nid);
     $file = $node->{$field_name}->entity;
     $url = file_url_transform_relative(file_create_url(ImageStyle::load('medium')->buildUrl($file->getFileUri())));
     $this->assertTrue($this->cssSelect('img[width=40][height=20][class=image-style-medium][src="' . $url . '"]'));
     // Add alt/title fields to the image and verify that they are displayed.
     $image = array('#theme' => 'image', '#uri' => $file->getFileUri(), '#alt' => $alt, '#title' => $this->randomMachineName(), '#width' => 40, '#height' => 20);
     $edit = array($field_name . '[0][alt]' => $image['#alt'], $field_name . '[0][title]' => $image['#title']);
     $this->drupalPostForm('node/' . $nid . '/edit', $edit, t('Save and keep published'));
     $default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
     $this->assertRaw($default_output, 'Image displayed using user supplied alt and title attributes.');
     // Verify that alt/title longer than allowed results in a validation error.
     $test_size = 2000;
     $edit = array($field_name . '[0][alt]' => $this->randomMachineName($test_size), $field_name . '[0][title]' => $this->randomMachineName($test_size));
     $this->drupalPostForm('node/' . $nid . '/edit', $edit, t('Save and keep published'));
     $schema = $field->getFieldStorageDefinition()->getSchema();
     $this->assertRaw(t('Alternative text cannot be longer than %max characters but is currently %length characters long.', array('%max' => $schema['columns']['alt']['length'], '%length' => $test_size)));
     $this->assertRaw(t('Title cannot be longer than %max characters but is currently %length characters long.', array('%max' => $schema['columns']['title']['length'], '%length' => $test_size)));
     // Set cardinality to unlimited and add upload a second image.
     // The image widget is extending on the file widget, but the image field
     // type does not have the 'display_field' setting which is expected by
     // the file widget. This resulted in notices before when cardinality is not
     // 1, so we need to make sure the file widget prevents these notices by
     // providing all settings, even if they are not used.
     // @see FileWidget::formMultipleElements().
     $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/storage', array('cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), t('Save field settings'));
     $edit = array('files[' . $field_name . '_1][]' => drupal_realpath($test_image->uri));
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
     // Add the required alt text.
     $this->drupalPostForm(NULL, [$field_name . '[1][alt]' => $alt], t('Save and keep published'));
     $this->assertText(format_string('Article @title has been updated.', array('@title' => $node->getTitle())));
     // Assert ImageWidget::process() calls FieldWidget::process().
     $this->drupalGet('node/' . $node->id() . '/edit');
     $edit = array('files[' . $field_name . '_2][]' => drupal_realpath($test_image->uri));
     $this->drupalPostAjaxForm(NULL, $edit, $field_name . '_2_upload_button');
     $this->assertNoRaw('<input multiple type="file" id="edit-' . strtr($field_name, '_', '-') . '-2-upload" name="files[' . $field_name . '_2][]" size="22" class="js-form-file form-file">');
     $this->assertRaw('<input multiple type="file" id="edit-' . strtr($field_name, '_', '-') . '-3-upload" name="files[' . $field_name . '_3][]" size="22" class="js-form-file form-file">');
 }
开发者ID:Wylbur,项目名称:gj,代码行数:73,代码来源:ImageFieldDisplayTest.php


示例17: testFieldFormatterConf

 /**
  * Test configuration options that are specific to the Juicebox field
  * formatter.
  */
 public function testFieldFormatterConf()
 {
     $node = $this->node;
     // Do a set of control requests as an anon user that will also prime any
     // caches.
     $this->drupalGet('node/' . $node->id());
     $this->assertResponse(200, 'Control request of test node was successful.');
     $this->drupalGet('juicebox/xml/field/node/' . $node->id() . '/' . $this->instFieldName . '/full');
     $this->assertResponse(200, 'Control request of XML was successful.');
     // Alter field formatter specific settings to contain custom values.
     $this->drupalLogin($this->webUser);
     $this->drupalPostAjaxForm('admin/structure/types/manage/' . $this->instBundle . '/display', array(), $this->instFieldName . '_settings_edit', NULL, array(), array(), 'entity-view-display-edit-form');
     $edit = array('fields[' . $this->instFieldName . '][settings_edit_form][settings][image_style]' => '', 'fields[' . $this->instFieldName . '][settings_edit_form][settings][thumb_style]' => 'thumbnail', 'fields[' . $this->instFieldName . '][settings_edit_form][settings][caption_source]' => 'alt', 'fields[' . $this->instFieldName . '][settings_edit_form][settings][title_source]' => 'title');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertText(t('Your settings have been saved.'), 'Gallery configuration changes saved.');
     // Get the urls to the image and thumb derivatives expected.
     $uri = \Drupal\file\Entity\File::load($node->{$this->instFieldName}[0]->target_id)->getFileUri();
     $test_formatted_image_url = file_create_url($uri);
     $test_formatted_thumb_url = entity_load('image_style', 'thumbnail')->buildUrl($uri);
     // Check for correct embed markup as anon user.
     $this->drupalLogout();
     $this->drupalGet('node/' . $node->id());
     $this->assertRaw(Html::escape(file_url_transform_relative($test_formatted_image_url)), 'Test styled image found in embed code');
     // Check for correct XML.
     $this->drupalGet('juicebox/xml/field/node/' . $node->id() . '/' . $this->instFieldName . '/full');
     $this->assertRaw('imageURL="' . Html::escape($test_formatted_image_url), 'Test styled image found in XML.');
     $this->assertRaw('thumbURL="' . Html::escape($test_formatted_thumb_url), 'Test styled thumbnail found in XML.');
     // Note the intended title and caption text does not contain any block-level
     // tags as long as the global title and caption output filter is working.
     // So this acts as a test for that feature as well.
     $this->assertRaw('<title><![CDATA[Some title text for field ' . $this->instFieldName . ' on node ' . $node->id() . ']]></title>', 'Image title text found in XML');
     $this->assertRaw('<caption><![CDATA[Some alt text for field ' . $this->instFieldName . ' on node ' . $node->id() . ' &lt;strong&gt;with formatting&lt;/strong&gt;]]></caption>', 'Image caption text found in XML');
     // Now that we have title and caption data set, also ensure this text can
     // be found in search results. First we update the search index by marking
     // our test node as dirty and running cron.
     $this->drupalLogin($this->webUser);
     $this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save and keep published'));
     $this->cronRun();
     $this->drupalPostForm('search', array('keys' => '"Some title text"'), t('Search'));
     $this->assertText('Test Juicebox Gallery Node', 'Juicebox node found in search for title text.');
     // The Juicebox javascript should have been excluded from the search results
     // page.
     $this->assertNoRaw('"configUrl":"', 'Juicebox Drupal.settings vars not included on search result page.');
 }
开发者ID:pulibrary,项目名称:recap,代码行数:48,代码来源:JuiceboxFieldFormatterCase.php


示例18: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $elements = array();
     $files = $this->getEntitiesToView($items, $langcode);
     // Early opt-out if the field is empty.
     if (empty($files)) {
         return $elements;
     }
     $url = NULL;
     // Check if the formatter involves a link.
     if ($this->getSetting('image_link') == 'content') {
         $entity = $items->getEntity();
         if (!$entity->isNew()) {
             $url = $entity->urlInfo();
         }
     } elseif ($this->getSetting('image_link') == 'file') {
         $link_file = TRUE;
     }
     // Collect cache tags to be added for each item in the field.
     $responsive_image_style = $this->responsiveImageStyleStorage->load($this->getSetting('responsive_image_style'));
     $image_styles_to_load = array();
     $cache_tags = [];
     if ($responsive_image_style) {
         $cache_tags = Cache::mergeTags($cache_tags, $responsive_image_style->getCacheTags());
         $image_styles_to_load = $responsive_image_style->getImageStyleIds();
     }
     $image_styles = $this->imageStyleStorage->loadMultiple($image_styles_to_load);
     foreach ($image_styles as $image_style) {
         $cache_tags = Cache::mergeTags($cache_tags, $image_style->getCacheTags());
     }
     foreach ($files as $delta => $file) {
         // Link the <picture> element to the original file.
         if (isset($link_file)) {
             $url = file_url_transform_relative(file_create_url($file->getFileUri()));
         }
         // Extract field item attributes for the theme function, and unset them
         // from the $item so that the field template does not re-render them.
         $item = $file->_referringItem;
         $item_attributes = $item->_attributes;
         unset($item->_attributes);
         $elements[$delta] = array('#theme' => 'responsive_image_formatter', '#item' => $item, '#item_attributes' => $item_attributes, '#responsive_image_style_id' => $responsive_image_style ? $responsive_image_style->id() : '', '#url' => $url, '#cache' => array('tags' => $cache_tags));
     }
     return $elements;
 }
开发者ID:318io,项目名称:318-io,代码行数:47,代码来源:ResponsiveImageFormatter.php


示例19: getJSSettings

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP file_validate_extensions函数代码示例发布时间:2022-05-15
下一篇:
PHP file_uri_target函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap