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


PHP ImageStyle::create方法代码示例

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


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

示例1: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->fileSystem = $this->container->get('file_system');
     $this->config('system.file')->set('default_scheme', 'public')->save();
     $this->imageStyle = ImageStyle::create(['name' => 'test']);
     $this->imageStyle->save();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:11,代码来源:ImageStyleCustomStreamWrappersTest.php

示例2: testEntityDisplayDependency

 /**
  * Tests the dependency between ImageStyle and entity display components.
  */
 public function testEntityDisplayDependency()
 {
     // Create two image styles.
     /** @var \Drupal\image\ImageStyleInterface $style */
     $style = ImageStyle::create(['name' => 'main_style']);
     $style->save();
     /** @var \Drupal\image\ImageStyleInterface $replacement */
     $replacement = ImageStyle::create(['name' => 'replacement_style']);
     $replacement->save();
     // Create a node-type, named 'note'.
     $node_type = NodeType::create(['type' => 'note']);
     $node_type->save();
     // Create an image field and attach it to the 'note' node-type.
     FieldStorageConfig::create(['entity_type' => 'node', 'field_name' => 'sticker', 'type' => 'image'])->save();
     FieldConfig::create(['entity_type' => 'node', 'field_name' => 'sticker', 'bundle' => 'note'])->save();
     // Create the default entity view display and set the 'sticker' field to use
     // the 'main_style' images style in formatter.
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
     $view_display = EntityViewDisplay::create(['targetEntityType' => 'node', 'bundle' => 'note', 'mode' => 'default', 'status' => TRUE])->setComponent('sticker', ['settings' => ['image_style' => 'main_style']]);
     $view_display->save();
     // Create the default entity form display and set the 'sticker' field to use
     // the 'main_style' images style in the widget.
     /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
     $form_display = EntityFormDisplay::create(['targetEntityType' => 'node', 'bundle' => 'note', 'mode' => 'default', 'status' => TRUE])->setComponent('sticker', ['settings' => ['preview_image_style' => 'main_style']]);
     $form_display->save();
     // Check that the entity displays exists before dependency removal.
     $this->assertNotNull(EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull(EntityFormDisplay::load($form_display->id()));
     // Delete the 'main_style' image style. Before that, emulate the UI process
     // of selecting a replacement style by setting the replacement image style
     // ID in the image style storage.
     /** @var \Drupal\image\ImageStyleStorageInterface $storage */
     $storage = $this->container->get('entity.manager')->getStorage($style->getEntityTypeId());
     $storage->setReplacementId('main_style', 'replacement_style');
     $style->delete();
     // Check that the entity displays exists after dependency removal.
     $this->assertNotNull($view_display = EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull($form_display = EntityFormDisplay::load($form_display->id()));
     // Check that the 'sticker' formatter component exists in both displays.
     $this->assertNotNull($formatter = $view_display->getComponent('sticker'));
     $this->assertNotNull($widget = $form_display->getComponent('sticker'));
     // Check that both displays are using now 'replacement_style' for images.
     $this->assertSame('replacement_style', $formatter['settings']['image_style']);
     $this->assertSame('replacement_style', $widget['settings']['preview_image_style']);
     // Delete the 'replacement_style' without setting a replacement image style.
     $replacement->delete();
     // The entity view and form displays exists after dependency removal.
     $this->assertNotNull($view_display = EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull($form_display = EntityFormDisplay::load($form_display->id()));
     // The 'sticker' formatter component should be hidden in view display.
     $this->assertNull($view_display->getComponent('sticker'));
     $this->assertTrue($view_display->get('hidden')['sticker']);
     // The 'sticker' widget component should be active in form displays, but the
     // image preview should be disabled.
     $this->assertNotNull($widget = $form_display->getComponent('sticker'));
     $this->assertSame('', $widget['settings']['preview_image_style']);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:60,代码来源:ImageStyleIntegrationTest.php

示例3: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->style = ImageStyle::create(['name' => 'style_foo', 'label' => $this->randomString()]);
     $this->style->save();
     $this->replacementStyle = ImageStyle::create(['name' => 'style_bar', 'label' => $this->randomString()]);
     $this->replacementStyle->save();
     $this->entityTypeManager = \Drupal::entityTypeManager();
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:12,代码来源:FormatterDependenciesTest.php

示例4: testImport

 /**
  * Tests importing image styles.
  */
 public function testImport()
 {
     $style = ImageStyle::create(['name' => 'test']);
     $style->addImageEffect(['id' => 'image_module_test_null']);
     $style->addImageEffect(['id' => 'image_module_test_null']);
     $style->save();
     $this->assertEqual(count($style->getEffects()), 2);
     $uuid = \Drupal::service('uuid')->generate();
     $style->set('effects', [$uuid => ['id' => 'image_module_test_null']]);
     $style->save();
     $style = ImageStyle::load('test');
     $this->assertEqual(count($style->getEffects()), 1);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:16,代码来源:ImageImportTest.php

示例5: testDevelSilent

 /**
  * Tests devel silent.
  */
 public function testDevelSilent()
 {
     // TODO Quickfix for dynamic_page_cache, enabled by default in the testing
     // profile.
     $this->container->get('module_installer')->uninstall(['dynamic_page_cache']);
     $web_user = $this->drupalCreateUser(['administer site configuration', 'access devel information', 'administer software updates']);
     $this->drupalLogin($web_user);
     // Ensure that devel is disabled if response come from routes that are
     // declared with '_devel_silent' requirement.
     $this->drupalGet('devel-silent/route-requirement');
     $this->assertText(t('"_devel_silent" route requirement forces devel to be inactive.'));
     // Ensure that devel doesn't interfere with non html response (e.g JsonResponse).
     $response = $this->drupalGet('devel-silent/json');
     $this->assertResponse(200);
     $expected = ['data' => 'Devel is active only on HtmlResponse.'];
     $this->assertIdentical(Json::decode($response), $expected);
     // Ensure that devel doesn't interfere with private image style creation
     // and with BinaryFileResponse response.
     $style = ImageStyle::create(['name' => 'zyx', 'label' => $this->randomString()]);
     $style->save();
     $image = current($this->drupalGetTestFiles('image'));
     $image_uri = file_unmanaged_copy($image->uri, 'private://');
     // Let the devel_test module know about this file, so it can claim
     // ownership in hook_file_download().
     \Drupal::state()->set('devel.test_file_download', $image_uri);
     $this->drupalGet($style->buildUrl($image_uri));
     $this->assertResponse(200);
     $this->assertRaw(file_get_contents($style->buildUri($image_uri)), 'URL returns expected file.');
     // Ensure that devel doesn't interfere with private files and with
     // BinaryFileResponse response.
     $file = File::create(['uid' => $web_user->id(), 'filename' => 'drupal.txt', 'uri' => 'private://devel.txt', 'filemime' => 'text/plain', 'status' => FILE_STATUS_PERMANENT]);
     file_put_contents($file->getFileUri(), 'Hello world!');
     $file->save();
     // Let the image_module_test module know about this file, so it can claim
     // ownership in hook_file_download().
     \Drupal::state()->set('devel.test_file_download', $file->getFileUri());
     $this->drupalGet($file->url());
     $this->assertResponse(200);
     $this->assertRaw(file_get_contents($file->getFileUri()), 'URL returns expected file.');
 }
开发者ID:ABaldwinHunter,项目名称:durhamatletico-cms,代码行数:43,代码来源:DevelSilentTest.php

示例6: testImage

 /**
  * Tests integration with image module.
  */
 public function testImage()
 {
     /** @var \Drupal\image\ImageStyleInterface $style */
     $style = ImageStyle::create(['name' => 'foo']);
     $style->save();
     // Create a new image field 'bar' to be used in 'entity_test_fields' view.
     FieldStorageConfig::create(['entity_type' => 'entity_test', 'field_name' => 'bar', 'type' => 'image'])->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'bundle' => 'entity_test', 'field_name' => 'bar'])->save();
     /** @var \Drupal\views\ViewEntityInterface $view */
     $view = View::load('entity_test_fields');
     $display =& $view->getDisplay('default');
     // Add the 'bar' image field to 'entity_test_fields' view.
     $display['display_options']['fields']['bar'] = ['id' => 'bar', 'field' => 'bar', 'plugin_id' => 'field', 'table' => 'entity_test__bar', 'entity_type' => 'entity_test', 'entity_field' => 'bar', 'type' => 'image', 'settings' => ['image_style' => 'foo', 'image_link' => '']];
     $view->save();
     $dependencies = $view->getDependencies() + ['config' => []];
     // Checks that style 'foo' is a dependency of view 'entity_test_fields'.
     $this->assertTrue(in_array('image.style.foo', $dependencies['config']));
     // Delete the 'foo' image style.
     $style->delete();
     // Checks that the view has been deleted too.
     $this->assertNull(View::load('entity_test_fields'));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:25,代码来源:ViewsConfigDependenciesIntegrationTest.php

示例7: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->style = ImageStyle::create(array('name' => 'style_foo', 'label' => $this->randomString()));
     $this->style->save();
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:6,代码来源:ImageStylesPathAndUrlTest.php

示例8: testImageDimensions

 /**
  * Test styled image dimensions cumulatively.
  */
 function testImageDimensions()
 {
     $image_factory = $this->container->get('image.factory');
     // Create a working copy of the file.
     $files = $this->drupalGetTestFiles('image');
     $file = reset($files);
     $original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
     // Create a style.
     /** @var $style \Drupal\image\ImageStyleInterface */
     $style = entity_create('image_style', array('name' => 'test', 'label' => 'Test'));
     $style->save();
     $generated_uri = 'public://styles/test/public/' . \Drupal::service('file_system')->basename($original_uri);
     $url = $style->buildUrl($original_uri);
     $variables = array('#theme' => 'image_style', '#style_name' => 'test', '#uri' => $original_uri, '#width' => 40, '#height' => 20);
     // Verify that the original image matches the hard-coded values.
     $image_file = $image_factory->get($original_uri);
     $this->assertEqual($image_file->getWidth(), $variables['#width']);
     $this->assertEqual($image_file->getHeight(), $variables['#height']);
     // Scale an image that is wider than it is high.
     $effect = array('id' => 'image_scale', 'data' => array('width' => 120, 'height' => 90, 'upscale' => TRUE), 'weight' => 0);
     $style->addImageEffect($effect);
     $style->save();
     $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="120" height="60" alt="" class="image-style-test" />');
     $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
     $this->drupalGet($url);
     $this->assertResponse(200, 'Image was generated at the URL.');
     $this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
     $image_file = $image_factory->get($generated_uri);
     $this->assertEqual($image_file->getWidth(), 120);
     $this->assertEqual($image_file->getHeight(), 60);
     // Rotate 90 degrees anticlockwise.
     $effect = array('id' => 'image_rotate', 'data' => array('degrees' => -90, 'random' => FALSE), 'weight' => 1);
     $style->addImageEffect($effect);
     $style->save();
     $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="60" height="120" alt="" class="image-style-test" />');
     $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
     $this->drupalGet($url);
     $this->assertResponse(200, 'Image was generated at the URL.');
     $this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
     $image_file = $image_factory->get($generated_uri);
     $this->assertEqual($image_file->getWidth(), 60);
     $this->assertEqual($image_file->getHeight(), 120);
     // Scale an image that is higher than it is wide (rotated by previous effect).
     $effect = array('id' => 'image_scale', 'data' => array('width' => 120, 'height' => 90, 'upscale' => TRUE), 'weight' => 2);
     $style->addImageEffect($effect);
     $style->save();
     $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="45" height="90" alt="" class="image-style-test" />');
     $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
     $this->drupalGet($url);
     $this->assertResponse(200, 'Image was generated at the URL.');
     $this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
     $image_file = $image_factory->get($generated_uri);
     $this->assertEqual($image_file->getWidth(), 45);
     $this->assertEqual($image_file->getHeight(), 90);
     // Test upscale disabled.
     $effect = array('id' => 'image_scale', 'data' => array('width' => 400, 'height' => 200, 'upscale' => FALSE), 'weight' => 3);
     $style->addImageEffect($effect);
     $style->save();
     $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="45" height="90" alt="" class="image-style-test" />');
     $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
     $this->drupalGet($url);
     $this->assertResponse(200, 'Image was generated at the URL.');
     $this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
     $image_file = $image_factory->get($generated_uri);
     $this->assertEqual($image_file->getWidth(), 45);
     $this->assertEqual($image_file->getHeight(), 90);
     // Add a desaturate effect.
     $effect = array('id' => 'image_desaturate', 'data' => array(), 'weight' => 4);
     $style->addImageEffect($effect);
     $style->save();
     $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="45" height="90" alt="" class="image-style-test" />');
     $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
     $this->drupalGet($url);
     $this->assertResponse(200, 'Image was generated at the URL.');
     $this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
     $image_file = $image_factory->get($generated_uri);
     $this->assertEqual($image_file->getWidth(), 45);
     $this->assertEqual($image_file->getHeight(), 90);
     // Add a random rotate effect.
     $effect = array('id' => 'image_rotate', 'data' => array('degrees' => 180, 'random' => TRUE), 'weight' => 5);
     $style->addImageEffect($effect);
     $style->save();
     $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" alt="" class="image-style-test" />');
     $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
     $this->drupalGet($url);
     $this->assertResponse(200, 'Image was generated at the URL.');
     $this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
     // Add a crop effect.
     $effect = array('id' => 'image_crop', 'data' => array('width' => 30, 'height' => 30, 'anchor' => 'center-center'), 'weight' => 6);
     $style->addImageEffect($effect);
     $style->save();
     $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="30" height="30" alt="" class="image-style-test" />');
     $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
     $this->drupalGet($url);
     $this->assertResponse(200, 'Image was generated at the URL.');
     $this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
     $image_file = $image_factory->get($generated_uri);
//.........这里部分代码省略.........
开发者ID:ddrozdik,项目名称:dmaps,代码行数:101,代码来源:ImageDimensionsTest.php

示例9: testDevelSilent

 /**
  * Tests devel silent.
  */
 public function testDevelSilent()
 {
     // TODO Quickfix for dynamic_page_cache, enabled by default in the testing
     // profile.
     $this->container->get('module_installer')->uninstall(['dynamic_page_cache']);
     // Enable timer so we can test if devel_silent() works properly by checking
     // the output of the page.
     \Drupal::configFactory()->getEditable('devel.settings')->set('timer', TRUE)->save();
     $web_user = $this->drupalCreateUser(['administer site configuration', 'access devel information', 'administer software updates']);
     $this->drupalLogin($web_user);
     $this->drupalGet('');
     $this->assertText('Page execution time was');
     // Ensure that devel is disabled if the request has XDEBUG_PROFILE
     // parameter set. Get the user profile page so we are sure that we are not
     // redirected and we don't lose the query string parameter.
     $this->drupalGet('user/' . $web_user->id(), ['query' => ['XDEBUG_PROFILE' => '1']]);
     $this->assertNoText('Page execution time was');
     // TODO this assertion seems to break testbot, we need to investigate.
     // Ensure that devel is disabled if the request come from Apache Benchmark.
     // $this->drupalGet('', [], ['User-Agent: ApacheBench/1.0']);
     // $this->assertNoText('Page execution time was');
     // Ensure that devel is disabled on the front controller update.php.
     $this->drupalGet(Url::fromRoute('system.db_update'));
     $this->assertResponse(200);
     $this->assertNoText('Page execution time was');
     // Ensure that devel is disabled if $GLOBALS['devel_shutdown'] is set
     // somewhere in the code.
     $this->drupalGet('devel-silent/global-shoutdown');
     $this->assertText(t('$GLOBALS[\'devel_shutdown\'] = FALSE forces devel to be inactive.'));
     $this->assertNoText('Page execution time was');
     // Ensure that devel is disabled if response come from routes that are
     // declared with '_devel_silent' requirement.
     $this->drupalGet('devel-silent/route-requirement');
     $this->assertText(t('"_devel_silent" route requirement forces devel to be inactive.'));
     $this->assertNoText('Page execution time was');
     // Ensure that devel doesn't interfere with non html response (e.g JsonResponse).
     $response = $this->drupalGet('devel-silent/json');
     $this->assertResponse(200);
     $expected = ['data' => 'Devel is active only on HtmlResponse.'];
     $this->assertIdentical(Json::decode($response), $expected);
     // Ensure that devel doesn't interfere with private image style creation
     // and with BinaryFileResponse response.
     $style = ImageStyle::create(['name' => 'zyx', 'label' => $this->randomString()]);
     $style->save();
     $image = current($this->drupalGetTestFiles('image'));
     $image_uri = file_unmanaged_copy($image->uri, 'private://');
     // Let the devel_test module know about this file, so it can claim
     // ownership in hook_file_download().
     \Drupal::state()->set('devel.test_file_download', $image_uri);
     $this->drupalGet($style->buildUrl($image_uri));
     $this->assertResponse(200);
     $this->assertRaw(file_get_contents($style->buildUri($image_uri)), 'URL returns expected file.');
     $this->assertNoText('Page execution time was');
     // Ensure that devel doesn't interfere with private files and with
     // BinaryFileResponse response.
     $file = File::create(['uid' => $web_user->id(), 'filename' => 'drupal.txt', 'uri' => 'private://devel.txt', 'filemime' => 'text/plain', 'status' => FILE_STATUS_PERMANENT]);
     file_put_contents($file->getFileUri(), 'Hello world!');
     $file->save();
     // Let the image_module_test module know about this file, so it can claim
     // ownership in hook_file_download().
     \Drupal::state()->set('devel.test_file_download', $file->getFileUri());
     $this->drupalGet($file->url());
     $this->assertResponse(200);
     $this->assertRaw(file_get_contents($file->getFileUri()), 'URL returns expected file.');
     $this->assertNoText('Page execution time was');
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:69,代码来源:DevelSilentTest.php

示例10: 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

示例11: testImageStyleAccess

 /**
  * Tests access for the image style listing.
  */
 public function testImageStyleAccess()
 {
     $style = ImageStyle::create(array('name' => 'style_foo', 'label' => $this->randomString()));
     $style->save();
     $this->drupalGet('admin/config/media/image-styles');
     $this->clickLink(t('Edit'));
     $this->assertRaw(t('Select a new effect'));
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:11,代码来源:ImageAdminStylesTest.php


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