Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $query = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'team_member')->sort('field_order', 'ASC');
     $nids = $query->execute();
     $nodes = node_load_multiple($nids);
     //$nodes = entity_load_multiple('node', $nids);
     $ind = 1;
     $output = '<div class="tabbable tabs-left tabcordion">
             <ul class="nav nav-tabs">';
     foreach ($nodes as $node) {
         $class = $ind == 1 ? 'active' : '';
         $output .= '<li class="' . $class . '"><a data-target="#team_member_tab' . $ind . '" data-toggle="tab">' . $node->title->value . '<span>' . $node->get('field_designation')->value . '</span></a></li>';
         $ind++;
     }
     $ind = 1;
     $output .= '</ul>
         <div class="tab-content">';
     foreach ($nodes as $node) {
         $class = $ind == 1 ? 'active' : '';
         if (is_object($node->field_image->entity)) {
             $path = $node->field_image->entity->getFileUri();
             $url = ImageStyle::load('person_picture')->buildUrl($path);
             $tab_content_html = '<div class="row"><div class="col-md-3"><img src="' . $url . '" alt=""></div><div class="col-md-9">' . $node->get('body')->value . '</div> </div>';
         } else {
             $tab_content_html = '<div>' . $node->get('body')->value . '</div>';
         }
         $output .= '<div class="tab-pane ' . $class . '" id="team_member_tab' . $ind . '"> ' . $tab_content_html . ' </div>';
         $ind++;
     }
     $output .= '</div>
       </div>';
     return array('#type' => 'markup', '#markup' => $output, '#attached' => array('library' => array('barney_river_utilities/tabcordion', 'barney_river_utilities/tabcordion_hook')));
 }
Ejemplo n.º 2
0
 /**
  * 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 = $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.');
 }
 /**
  * {@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;
     }
     $image_style_setting = $this->getSetting('image_style');
     // Determine if Image style is required.
     $image_style = NULL;
     if (!empty($image_style_setting)) {
         $image_style = entity_load('image_style', $image_style_setting);
     }
     foreach ($files as $delta => $file) {
         $image_uri = $file->getFileUri();
         // Get image style URL
         if ($image_style) {
             $image_uri = ImageStyle::load($image_style->getName())->buildUrl($image_uri);
         } else {
             // Get absolute path for original image
             $image_uri = $file->url();
         }
         $elements[$delta] = array('#markup' => $image_uri);
     }
     return $elements;
 }
 /**
  * Watermark operations test.
  */
 public function doTestWatermarkOperations()
 {
     $image_factory = $this->container->get('image.factory');
     $test_file = drupal_get_path('module', 'simpletest') . '/files/image-1.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);
     $watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png';
     $watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME);
     $effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 1, 'y_offset' => 1, 'opacity' => 100, 'watermark_image' => $watermark_uri]];
     $uuid = $this->addEffectToTestStyle($effect);
     // Load Image Style.
     $image_style = ImageStyle::load('image_effects_test');
     // Check that ::applyEffect generates image with expected watermark.
     $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
     $image = $image_factory->get($generated_uri, 'gd');
     $watermark = $image_factory->get($watermark_uri, 'gd');
     $this->assertFalse($this->colorsAreEqual($this->getPixelColor($watermark, 0, 0), $this->getPixelColor($image, 0, 0)));
     $this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 0), $this->getPixelColor($image, 1, 1)));
     $this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 1), $this->getPixelColor($image, 1, 2)));
     $this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 3), $this->getPixelColor($image, 1, 4)));
     // Remove effect.
     $this->removeEffectFromTestStyle($uuid);
     // Test for watermark PNG image with full transparency set, 100% opacity
     // watermark.
     $test_file = drupal_get_path('module', 'image_effects') . '/tests/images/fuchsia.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);
     $watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png';
     $watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME);
     $effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 0, 'y_offset' => 0, 'opacity' => 100, 'watermark_image' => $watermark_uri]];
     $uuid = $this->addEffectToTestStyle($effect);
     // Load Image Style.
     $image_style = ImageStyle::load('image_effects_test');
     // Check that ::applyEffect generates image with expected transparency.
     $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
     $image = $image_factory->get($generated_uri, 'gd');
     $this->assertTrue($this->colorsAreEqual($this->getPixelColor($image, 0, 19), $this->fuchsia));
     // Remove effect.
     $this->removeEffectFromTestStyle($uuid);
     // Test for watermark PNG image with full transparency set, 50% opacity
     // watermark.
     $test_file = drupal_get_path('module', 'image_effects') . '/tests/images/fuchsia.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);
     $watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png';
     $watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME);
     $effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 0, 'y_offset' => 0, 'opacity' => 50, 'watermark_image' => $watermark_uri]];
     $uuid = $this->addEffectToTestStyle($effect);
     // Load Image Style.
     $image_style = ImageStyle::load('image_effects_test');
     // Check that ::applyEffect generates image with expected alpha.
     $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
     $image = $image_factory->get($generated_uri, 'gd');
     $this->assertTrue($this->colorsAreEqual($this->getPixelColor($image, 0, 19), $this->fuchsia));
     // GD and ImageMagick return slightly different colors, use the
     // ::colorsAreClose method.
     $this->assertTrue($this->colorsAreClose($this->getPixelColor($image, 39, 0), [127, 127, 127, 0]));
     // Remove effect.
     $this->removeEffectFromTestStyle($uuid);
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $elements = [];
     $thumb_image_style = $this->getSetting('thumbnail_image_style');
     $popup_image_style = $this->getSetting('popup_image_style');
     $gallery_type = $this->getSetting('gallery_type');
     $files = $this->getEntitiesToView($items, $langcode);
     foreach ($files as $delta => $file) {
         $image_uri = $file->getFileUri();
         $popup_image_path = !empty($popup_image_style) ? ImageStyle::load($popup_image_style)->buildUrl($image_uri) : $image_uri;
         // Depending on the outcome of https://www.drupal.org/node/2622586,
         // Either a class will need to be added to the $url object,
         // Or a custom theme function might be needed to do so.
         // For the time being, 'a' is used as the delegate in magnific-popup.js.
         $url = Url::fromUri(file_create_url($popup_image_path));
         $item = $file->_referringItem;
         $item_attributes = $file->_attributes;
         unset($file->_attributes);
         $item_attributes['class'][] = 'mfp-thumbnail';
         if ($gallery_type === 'first_item' && $delta > 0) {
             $elements[$delta] = ['#theme' => 'image_formatter', '#url' => $url, '#attached' => ['library' => ['magnific_popup/magnific_popup']]];
         } else {
             $elements[$delta] = ['#theme' => 'image_formatter', '#item' => $item, '#item_attributes' => $item_attributes, '#image_style' => $thumb_image_style, '#url' => $url, '#attached' => ['library' => ['magnific_popup/magnific_popup']]];
         }
     }
     return $elements;
 }
 /**
  * Color Shift operations test.
  */
 public function doTestColorshiftOperations()
 {
     $image_factory = $this->container->get('image.factory');
     // Test on the PNG test image.
     $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 data.
     $test_data = ['#FF0000' => [$this->red, $this->yellow, $this->transparent, $this->fuchsia], '#00FF00' => [$this->yellow, $this->green, $this->transparent, $this->cyan], '#0000FF' => [$this->fuchsia, $this->cyan, $this->transparent, $this->blue], '#929BEF' => [[255, 155, 239, 0], [146, 255, 239, 0], $this->transparent, [146, 155, 255, 0]]];
     foreach ($test_data as $key => $colors) {
         // Add Color Shift effect to the test image style.
         $effect = ['id' => 'image_effects_color_shift', 'data' => ['RGB][hex' => $key]];
         $uuid = $this->addEffectToTestStyle($effect);
         // Load Image Style.
         $image_style = ImageStyle::load('image_effects_test');
         // Check that ::applyEffect generates image with expected color shift.
         $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
         $image = $image_factory->get($generated_uri, 'gd');
         $this->assertTrue($this->colorsAreEqual($colors[0], $this->getPixelColor($image, 0, 0)));
         $this->assertTrue($this->colorsAreEqual($colors[1], $this->getPixelColor($image, 39, 0)));
         $this->assertTrue($this->colorsAreEqual($colors[2], $this->getPixelColor($image, 0, 19)));
         $this->assertTrue($this->colorsAreEqual($colors[3], $this->getPixelColor($image, 39, 19)));
         // Remove effect.
         $uuid = $this->removeEffectFromTestStyle($uuid);
     }
 }
 /**
  * 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());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function transformDimensions(array &$dimensions, $uri)
 {
     if (!isset($dimensions['width']) || !isset($dimensions['height'])) {
         // We cannot know which preset would be executed and thus cannot know the
         // resulting dimensions, unless both styles return the same dimensions:
         $landscape_dimensions = $portrait_dimensions = $dimensions;
         /* @var ImageStyle $landscape_style */
         $landscape_style = ImageStyle::load($this->configuration['landscape']);
         $landscape_style->transformDimensions($landscape_dimensions, $uri);
         /* @var ImageStyle $portrait_style */
         $portrait_style = ImageStyle::load($this->configuration['portrait']);
         $portrait_style->transformDimensions($portrait_dimensions, $uri);
         if ($landscape_dimensions == $portrait_dimensions) {
             $dimensions = $landscape_dimensions;
         } else {
             $dimensions['width'] = $dimensions['height'] = NULL;
         }
     } else {
         $ratio_adjustment = isset($this->configuration['ratio_adjustment']) ? floatval($this->configuration['ratio_adjustment']) : 1;
         $aspect = $dimensions['width'] / $dimensions['height'];
         $style_name = $aspect * $ratio_adjustment > 1 ? $this->configuration['landscape'] : $this->configuration['portrait'];
         /* @var ImageStyle $style */
         $style = ImageStyle::load($style_name);
         $style->transformDimensions($dimensions, $uri);
     }
 }
 /**
  * Contrast operations test.
  */
 public function doTestContrastOperations()
 {
     $image_factory = $this->container->get('image.factory');
     $image_toolkit_id = $image_factory->getToolkitId();
     // Test on the PNG test image.
     $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 data.
     $test_data = ['0' => [$this->red, $this->green, $this->transparent, $this->blue], '-50' => [$image_toolkit_id === 'imagemagick' ? array(180, 75, 75, 0) : array(159, 95, 95, 0), $image_toolkit_id === 'imagemagick' ? array(75, 180, 75, 0) : array(95, 159, 95, 0), $this->transparent, $image_toolkit_id === 'imagemagick' ? array(75, 75, 180, 0) : array(95, 95, 159, 0)], '-100' => [$image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0), $image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0), $this->transparent, $image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0)], '50' => [array(255, 0, 0, 0), array(0, 255, 0, 0), $this->transparent, array(0, 0, 255, 0)], '100' => [array(255, 0, 0, 0), array(0, 255, 0, 0), $this->transparent, array(0, 0, 255, 0)]];
     foreach ($test_data as $key => $colors) {
         // Add contrast effect to the test image style.
         $effect = ['id' => 'image_effects_contrast', 'data' => ['level' => $key]];
         $uuid = $this->addEffectToTestStyle($effect);
         // Load Image Style.
         $image_style = ImageStyle::load('image_effects_test');
         // Check that ::applyEffect generates image with expected contrast.
         $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
         $image = $image_factory->get($generated_uri, 'gd');
         $this->assertTrue($this->colorsAreEqual($colors[0], $this->getPixelColor($image, 0, 0)));
         $this->assertTrue($this->colorsAreEqual($colors[1], $this->getPixelColor($image, 39, 0)));
         $this->assertTrue($this->colorsAreEqual($colors[2], $this->getPixelColor($image, 0, 19)));
         $this->assertTrue($this->colorsAreEqual($colors[3], $this->getPixelColor($image, 39, 19)));
         // Remove effect.
         $uuid = $this->removeEffectFromTestStyle($uuid);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $grouping = NULL)
 {
     // Load logo image.
     $rendered_image = NULL;
     if (!empty($grouping->logo_fid)) {
         $file = File::load($grouping->logo_fid);
         if ($file) {
             $logo_url = ImageStyle::load('ea_groupings_200x200')->buildUrl($file->getFileUri());
             $image_array = array('#theme' => 'image', '#uri' => $logo_url, '#alt' => $this->t('Logo for @grouping', array('@grouping' => $grouping->title)), '#title' => $this->t('@grouping', array('@grouping' => $grouping->title)));
             $rendered_image = \Drupal::service('renderer')->render($image_array);
         }
     }
     // Construct form.
     $form = array();
     $form['gid'] = array('#type' => 'value', '#value' => $grouping->gid);
     $form['add'] = array('#type' => 'fieldset', '#description' => $this->t('Update grouping'), '#title' => $this->t('Edit grouping'));
     $form['add']['title'] = array('#type' => 'textfield', '#title' => $this->t('Title'), '#description' => $this->t('Title of grouping'), '#size' => 20, '#maxlength' => 20, '#required' => FALSE, '#default_value' => $grouping->title);
     $form['add']['description'] = array('#type' => 'textarea', '#title' => $this->t('Description'), '#description' => $this->t('A short description of the grouping'), '#required' => FALSE, '#default_value' => $grouping->description);
     $form['add']['logo'] = array('#type' => 'markup', '#markup' => $rendered_image);
     $form['add']['logo_fid'] = array('#title' => $this->t('Update logo'), '#type' => 'managed_file', '#description' => $this->t('Upload a logo for the grouping'), '#default_value' => NULL, '#upload_location' => 'public://logos/');
     $form['add']['time_zone'] = array('#title' => $this->t('Timezone'), '#type' => 'select', '#description' => $this->t('Select a time zone for the grouping'), '#options' => _ea_groupings_get_time_zones(), '#default_value' => $grouping->time_zone);
     $form['add']['parent_gid'] = array('#type' => 'select', '#description' => $this->t('Select a parent grouping'), '#options' => _ea_groupings_get_groupings_list(FALSE, $grouping->gid), '#disabled' => _ea_groupings_is_parent($grouping->gid), '#default_value' => $grouping->parent_gid);
     $form['add']['submit'] = array('#type' => 'submit', '#name' => 'add_group', '#value' => $this->t('Update grouping'), '#weight' => 100);
     $form['add']['old_title'] = array('#type' => 'value', '#value' => $grouping->title);
     $form['add']['old_logo_fid'] = array('#type' => 'value', '#value' => $grouping->logo_fid);
     $form['add']['old_parent_gid'] = array('#type' => 'value', '#value' => $grouping->parent_gid);
     return $form;
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function renderThumbnail($image_style, $link_url)
 {
     $this->downloadThumbnail();
     $output = ['#theme' => 'image', '#uri' => !empty($image_style) ? ImageStyle::load($image_style)->buildUrl($this->getLocalThumbnailUri()) : $this->getLocalThumbnailUri()];
     if ($link_url) {
         $output = ['#type' => 'link', '#title' => $output, '#url' => $link_url];
     }
     return $output;
 }
 /**
  * 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);
 }
Ejemplo n.º 13
0
 /**
  * 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);
 }
 /**
  * Test basic passing migrations.
  */
 public function testPassingMigration()
 {
     $this->executeMigration('d6_imagecache_presets');
     /** @var \Drupal\image\Entity\ImageStyle $style */
     $style = ImageStyle::load('big_blue_cheese');
     // Check basic Style info.
     $this->assertIdentical('big_blue_cheese', $style->get('name'), 'ImageStyle name set correctly');
     $this->assertIdentical('big_blue_cheese', $style->get('label'), 'ImageStyle label set correctly');
     // Test effects.
     $effects = $style->getEffects();
     // Check crop effect.
     $this->assertImageEffect($effects, 'image_crop', ['width' => 555, 'height' => 5555, 'anchor' => 'center-center']);
     // Check resize effect.
     $this->assertImageEffect($effects, 'image_resize', ['width' => 55, 'height' => 55]);
     // Check rotate effect.
     $this->assertImageEffect($effects, 'image_rotate', ['degrees' => 55, 'random' => FALSE, 'bgcolor' => '']);
 }
Ejemplo n.º 15
0
 /**
  * General test to flush a style.
  */
 function testFlush()
 {
     // Setup a style to be created and effects to add to it.
     $style_name = strtolower($this->randomMachineName(10));
     $style_label = $this->randomString();
     $style_path = 'admin/config/media/image-styles/manage/' . $style_name;
     $effect_edits = array('image_resize' => array('data[width]' => 100, 'data[height]' => 101), 'image_scale' => array('data[width]' => 110, 'data[height]' => 111, 'data[upscale]' => 1));
     // Add style form.
     $edit = array('name' => $style_name, 'label' => $style_label);
     $this->drupalPostForm('admin/config/media/image-styles/add', $edit, t('Create new style'));
     // Add each sample effect to the style.
     foreach ($effect_edits as $effect => $edit) {
         // Add the effect.
         $this->drupalPostForm($style_path, array('new' => $effect), t('Add'));
         if (!empty($edit)) {
             $this->drupalPostForm(NULL, $edit, t('Add effect'));
         }
     }
     // Load the saved image style.
     $style = ImageStyle::load($style_name);
     // Create an image for the 'public' wrapper.
     $image_path = $this->createSampleImage($style, 'public');
     // Expecting to find 2 images, one is the sample.png image shown in
     // image style preview.
     $this->assertEqual($this->getImageCount($style, 'public'), 2, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
     // Create an image for the 'private' wrapper.
     $image_path = $this->createSampleImage($style, 'private');
     $this->assertEqual($this->getImageCount($style, 'private'), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
     // Remove the 'image_scale' effect and updates the style, which in turn
     // forces an image style flush.
     $style_path = 'admin/config/media/image-styles/manage/' . $style->id();
     $uuids = array();
     foreach ($style->getEffects() as $uuid => $effect) {
         $uuids[$effect->getPluginId()] = $uuid;
     }
     $this->drupalPostForm($style_path . '/effects/' . $uuids['image_scale'] . '/delete', array(), t('Delete'));
     $this->assertResponse(200);
     $this->drupalPostForm($style_path, array(), t('Update style'));
     $this->assertResponse(200);
     // Post flush, expected 1 image in the 'public' wrapper (sample.png).
     $this->assertEqual($this->getImageCount($style, 'public'), 1, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style->label(), '%wrapper' => 'public')));
     // Post flush, expected no image in the 'private' wrapper.
     $this->assertEqual($this->getImageCount($style, 'private'), 0, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style->label(), '%wrapper' => 'private')));
 }
Ejemplo n.º 16
0
 /**
  * Asserts various aspects of an ImageStyle entity.
  *
  * @param string $id
  *   The expected image style ID.
  * @param string $label
  *   The expected image style label.
  * @param array $expected_effect_plugins
  *   An array of expected plugins attached to the image style entity
  * @param array $expected_effect_config
  *   An array of expected configuration for each effect in the image style
  */
 protected function assertEntity($id, $label, array $expected_effect_plugins, array $expected_effect_config)
 {
     $style = ImageStyle::load($id);
     $this->assertTrue($style instanceof ImageStyleInterface);
     /** @var \Drupal\image\ImageStyleInterface $style */
     $this->assertIdentical($id, $style->id());
     $this->assertIdentical($label, $style->label());
     // Check the number of effects associated with the style.
     $effects = $style->getEffects();
     $this->assertIdentical(count($effects), count($expected_effect_plugins));
     $index = 0;
     foreach ($effects as $effect) {
         $this->assertTrue($effect instanceof ImageEffectBase);
         $this->assertIdentical($expected_effect_plugins[$index], $effect->getPluginId());
         $config = $effect->getConfiguration();
         $this->assertIdentical($expected_effect_config[$index], $config['data']);
         $index++;
     }
 }
 /**
  * Strip metadata operations test.
  */
 public function doTestStripMetadataOperations()
 {
     $image_factory = $this->container->get('image.factory');
     $test_data = [['test_file' => drupal_get_path('module', 'image_effects') . '/misc/portrait-painting.jpg', 'original_orientation' => 8], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-test.jpg', 'original_orientation' => NULL], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-1.png', 'original_orientation' => NULL]];
     foreach ($test_data as $data) {
         // Get expected URIs.
         $test_file = drupal_get_path('module', 'image_effects') . '/misc/portrait-painting.jpg';
         $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 EXIF data.
         $exif = @exif_read_data(\Drupal::service('file_system')->realpath($original_uri));
         $this->assertEqual($data['original_orientation'], isset($exif['Orientation']) ? $exif['Orientation'] : NULL);
         // Load Image Style and process source image.
         $image_style = ImageStyle::load('image_effects_test');
         $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
         // Check that ::applyEffect strips EXIF metadata.
         $exif = @exif_read_data(\Drupal::service('file_system')->realpath($generated_uri));
         $this->assertEqual(NULL, isset($exif['Orientation']) ? $exif['Orientation'] : NULL);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function blockForm($form, FormStateInterface $form_state)
 {
     $form['featured'] = array('#type' => 'details', '#title' => t('Homepage Featured content'), '#open' => TRUE);
     for ($c = 1; $c <= 3; $c++) {
         $form['featured']['item' . $c] = array('#type' => 'details', '#title' => t('Item #' . $c), '#open' => TRUE);
         $file = $fid = NULL;
         $file_uuid = $this->configuration['featured_image' . $c];
         if (!empty($file_uuid)) {
             $fid = db_query("SELECT fid FROM {file_managed}\n          WHERE uuid = :uuid", array(':uuid' => $file_uuid))->fetchColumn();
         }
         $link = $this->configuration['featured_link' . $c];
         // Add preview image.
         if (!empty($fid)) {
             $file = !empty($fid) ? file_load($fid) : NULL;
             $url = ImageStyle::load('thumbnail')->buildUrl($file->getFileUri());
             $image = '<img src="' . $url . '" title="' . $file->name . '" width="100" />';
         }
         $form['featured']['item' . $c]['image' . $c] = array('#type' => 'managed_file', '#title' => t('Current Image'), '#required' => TRUE, '#field_prefix' => !empty($file) ? $image : NULL, '#description' => t('Image to be shown if no image is uploaded.'), '#default_value' => !empty($fid) ? array($fid) : NULL, '#upload_location' => 'public://oc_homepage/');
         $form['featured']['item' . $c]['link' . $c] = array('#type' => 'textfield', '#title' => t('Link'), '#required' => FALSE, '#default_value' => !empty($link) ? array($link) : NULL);
     }
     return $form;
 }
Ejemplo n.º 19
0
  /**
   * {@inheritdoc}
   */
  public function getSummary() {
    $summery = parent::getSummary();

    $summery[] = $this->t('Show image dimensions: @show_image_dimensions', [
      '@show_image_dimensions' => $this->configuration['images']['show_dimensions'] ? $this->t('Yes') : $this->t('No'),
    ]);

    $summery[] = $this->t('Show image thumbnail: @show_image_thumbnail', [
      '@show_image_thumbnail' => $this->configuration['images']['show_thumbnail'] ? $this->t('Yes') : $this->t('No'),
    ]);

    if ($this->moduleHandler->moduleExists('image') && $this->configuration['images']['show_thumbnail']) {
      $image_style = ImageStyle::load($this->configuration['images']['thumbnail_image_style']);
        if (!is_null($image_style)) {
          $summery[] = $this->t('Thumbnail style: @thumbnail_style', [
          '@thumbnail_style' =>  $image_style->label(),
        ]);
      }
    }

    return $summery;
  }
 /**
  * Test Focal Point change.
  */
 public function testFocalPointChange()
 {
     // Media ID used for testing.
     $mediaId = 9;
     $page = $this->getSession()->getPage();
     $this->drupalGet("media/{$mediaId}/edit");
     $this->createScreenshot($this->getScreenshotFolder() . '/MediaImageModifyTest_BeforeFocalPointChange_' . date('Ymd_His') . '.png');
     $this->getSession()->getDriver()->executeScript('var e = new jQuery.Event("click"); e.offsetX = 48; e.offsetY = 15; jQuery(".focal-point-wrapper img").trigger(e);');
     $this->createScreenshot($this->getScreenshotFolder() . '/MediaImageModifyTest_AfterFocalPointChange_' . date('Ymd_His') . '.png');
     $page->pressButton('Save and keep publish');
     $media = Media::load($mediaId);
     $img = $media->get('field_image')->target_id;
     $file = File::load($img);
     $path = $file->getFileUri();
     $derivativeUri = ImageStyle::load('teaser')->buildUri($path);
     ImageStyle::load('teaser')->createDerivative($path, $derivativeUri);
     $image1 = new Imagick($derivativeUri);
     $image2 = new Imagick(dirname(__FILE__) . '/../../fixtures/reference.jpg');
     $result = $image1->compareImages($image2, \Imagick::METRIC_MEANSQUAREERROR);
     $this->assertTrue($result[1] < 0.01, 'Images are identical');
     $image1->clear();
     $image2->clear();
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = array();
     $image_style_setting = $this->getSetting('image_style');
     // Determine if Image style is required.
     $image_style = NULL;
     if (!empty($image_style_setting)) {
         $image_style = entity_load('image_style', $image_style_setting);
     }
     foreach ($items as $delta => $item) {
         if ($item->entity) {
             $image_uri = $item->entity->getFileUri();
             // Get image style URL
             if ($image_style) {
                 $image_uri = ImageStyle::load($image_style->getName())->buildUrl($image_uri);
             } else {
                 // Get absolute path for original image
                 $image_uri = $item->entity->url();
             }
             $elements[$delta] = array('#markup' => $image_uri);
         }
     }
     return $elements;
 }
 /**
  * Tests that image fields in teasers have correct resources.
  */
 function testNodeTeaser()
 {
     // Set the display options for the teaser.
     $display_options = array('type' => 'image', 'settings' => array('image_style' => 'medium', 'image_link' => 'content'));
     $display = entity_get_display('node', 'article', 'teaser');
     $display->setComponent($this->fieldName, $display_options)->save();
     // Render the teaser.
     $node_render_array = node_view($this->node, 'teaser');
     $html = \Drupal::service('renderer')->renderRoot($node_render_array);
     // Parse the teaser.
     $parser = new \EasyRdf_Parser_Rdfa();
     $graph = new \EasyRdf_Graph();
     $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
     $parser->parse($graph, $html, 'rdfa', $base_uri);
     // Construct the node and image URIs for testing.
     $node_uri = $this->node->url('canonical', ['absolute' => TRUE]);
     $image_uri = ImageStyle::load('medium')->buildUrl($this->file->getFileUri());
     // Test relations from node to image.
     $expected_value = array('type' => 'uri', 'value' => $image_uri);
     $this->assertTrue($graph->hasProperty($node_uri, 'http://ogp.me/ns#image', $expected_value), 'Node to file relation found in RDF output (og:image).');
     // Test image type.
     $expected_value = array('type' => 'uri', 'value' => 'http://xmlns.com/foaf/0.1/Image');
     $this->assertTrue($graph->hasProperty($image_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Image type found in RDF output (foaf:Image).');
 }
Ejemplo n.º 23
0
 /**
  * Tests image style configuration import that does a delete.
  */
 function testConfigImport()
 {
     // Create a new style.
     $style_name = strtolower($this->randomMachineName(10));
     $style_label = $this->randomString();
     $style = entity_create('image_style', array('name' => $style_name, 'label' => $style_label));
     $style->save();
     // Create an image field that uses the new style.
     $field_name = strtolower($this->randomMachineName(10));
     $this->createImageField($field_name, 'article');
     entity_get_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'image', 'settings' => array('image_style' => $style_name)))->save();
     // Create a new node with an image attached.
     $test_image = current($this->drupalGetTestFiles('image'));
     $nid = $this->uploadNodeImage($test_image, $field_name, 'article', $this->randomMachineName());
     $node = Node::load($nid);
     // Get node field original image URI.
     $fid = $node->get($field_name)->target_id;
     $original_uri = File::load($fid)->getFileUri();
     // Test that image is displayed using newly created style.
     $this->drupalGet('node/' . $nid);
     $this->assertRaw($style->buildUrl($original_uri), format_string('Image displayed using style @style.', array('@style' => $style_name)));
     // Copy config to sync, and delete the image style.
     $sync = $this->container->get('config.storage.sync');
     $active = $this->container->get('config.storage');
     $this->copyConfig($active, $sync);
     $sync->delete('image.style.' . $style_name);
     $this->configImporter()->import();
     $this->assertFalse(ImageStyle::load($style_name), 'Style deleted after config import.');
     $this->assertEqual($this->getImageCount($style), 0, 'Image style was flushed after being deleted by config import.');
 }
 /**
  * Tests responsive image formatters linked to the file or node.
  *
  * @param string $link_type
  *   The link type to test. Either 'file' or 'content'.
  */
 private function assertResponsiveImageFieldFormattersLink($link_type)
 {
     $field_name = Unicode::strtolower($this->randomMachineName());
     $field_settings = array('alt_field_required' => 0);
     $this->createImageField($field_name, 'article', array('uri_scheme' => 'public'), $field_settings);
     // Create a new node with an image attached.
     $test_image = current($this->drupalGetTestFiles('image'));
     // Test the image linked to file formatter.
     $display_options = array('type' => 'responsive_image', 'settings' => array('image_link' => $link_type, 'responsive_image_style' => 'style_one'));
     entity_get_display('node', 'article', 'default')->setComponent($field_name, $display_options)->save();
     // Ensure that preview works.
     $this->previewNodeImage($test_image, $field_name, 'article');
     // Look for a picture tag in the preview output
     $this->assertPattern('/picture/');
     $nid = $this->uploadNodeImage($test_image, $field_name, 'article');
     $this->container->get('entity.manager')->getStorage('node')->resetCache(array($nid));
     $node = Node::load($nid);
     // Use the responsive image formatter linked to file formatter.
     $display_options = array('type' => 'responsive_image', 'settings' => array('image_link' => $link_type, 'responsive_image_style' => 'style_one'));
     entity_get_display('node', 'article', 'default')->setComponent($field_name, $display_options)->save();
     // Create a derivative so at least one MIME type will be known.
     $large_style = ImageStyle::load('large');
     $image_uri = File::load($node->{$field_name}->target_id)->getFileUri();
     $large_style->createDerivative($image_uri, $large_style->buildUri($image_uri));
     // Output should contain all image styles and all breakpoints.
     $this->drupalGet('node/' . $nid);
     $this->removeWhiteSpace();
     switch ($link_type) {
         case 'file':
             // Make sure the link to the file is present.
             $this->assertPattern('/<a(.*?)href="' . preg_quote(file_url_transform_relative(file_create_url($image_uri)), '/') . '"(.*?)><picture/');
             break;
         case 'content':
             // Make sure the link to the node is present.
             $this->assertPattern('/<a(.*?)href="' . preg_quote($node->url(), '/') . '"(.*?)><picture/');
             break;
     }
 }
Ejemplo n.º 25
0
 /**
  * Tests updating an image style during import.
  */
 protected function doImageStyleUpdate()
 {
     // Create a test image style with a known label.
     $name = 'image.style.thumbnail';
     /** @var $entity \Drupal\image\Entity\ImageStyle */
     $entity = ImageStyle::load('thumbnail');
     $plugin_collection = $entity->getPluginCollections()['effects'];
     $effects = $entity->get('effects');
     $effect_id = key($effects);
     $this->assertIdentical(100, $effects[$effect_id]['data']['height']);
     $effects[$effect_id]['data']['height'] = 50;
     $entity->set('effects', $effects);
     $entity->save();
     // Ensure the entity and plugin have the correct configuration.
     $this->assertIdentical($effects, $entity->get('effects'));
     $this->assertIdentical($effects, $plugin_collection->getConfiguration());
     $effects[$effect_id]['data']['height'] = -50;
     $entity->getPluginCollections()['effects']->setConfiguration($effects);
     $entity->save();
     // Ensure the entity and plugin have the correct configuration.
     $this->assertIdentical($effects, $entity->get('effects'));
     $this->assertIdentical($effects, $plugin_collection->getConfiguration());
     // Read the existing data, and prepare an altered version in staging.
     $custom_data = $original_data = $this->container->get('config.storage')->read($name);
     $effect_name = key($original_data['effects']);
     $custom_data['effects'][$effect_name]['data']['upscale'] = FALSE;
     $this->assertConfigUpdateImport($name, $original_data, $custom_data);
 }
Ejemplo n.º 26
0
 /**
  * Get the values from the form and provider required for the client.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The form state from the dialog submission.
  * @param \Drupal\video_embed_field\ProviderPluginInterface $provider
  *   The provider loaded from the user input.
  *
  * @return array
  *   An array of values sent to the client for use in the WYSIWYG.
  */
 protected function getClientValues(FormStateInterface $form_state, $provider)
 {
     // @todo Render the thumbnail to download it from the remote. Consider
     // making the download method public. https://www.drupal.org/node/2687077
     $provider->renderThumbnail(FALSE, FALSE);
     // All settings from the field formatter exist in the form and are relevant
     // for the rendering of the video.
     $video_formatter_settings = Video::defaultSettings();
     foreach ($video_formatter_settings as $key => $default) {
         $video_formatter_settings[$key] = $form_state->getValue($key);
     }
     return ['preview_thumbnail' => ImageStyle::load('video_embed_wysiwyg_preview')->buildUrl($provider->getLocalThumbnailUri()), 'video_url' => $form_state->getValue('video_url'), 'settings' => $video_formatter_settings, 'settings_summary' => $this->getVideoFormatterInstance($video_formatter_settings)->settingsSummary()];
 }
Ejemplo n.º 27
0
 /**
  * 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_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">');
 }
Ejemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 public function onDependencyRemoval(array $dependencies)
 {
     $changed = parent::onDependencyRemoval($dependencies);
     $style_id = $this->getSetting('image_style');
     /** @var \Drupal\image\ImageStyleInterface $style */
     if ($style_id && ($style = ImageStyle::load($style_id))) {
         if (!empty($dependencies[$style->getConfigDependencyKey()][$style->getConfigDependencyName()])) {
             $replacement_id = $this->imageStyleStorage->getReplacementId($style_id);
             // If a valid replacement has been provided in the storage, replace the
             // image style with the replacement and signal that the formatter plugin
             // settings were updated.
             if ($replacement_id && ImageStyle::load($replacement_id)) {
                 $this->setSetting('image_style', $replacement_id);
                 $changed = TRUE;
             }
         }
     }
     return $changed;
 }
Ejemplo n.º 29
0
 /**
  * Tests that data is exposed in the front page teasers.
  */
 protected function doFrontPageRdfaTests()
 {
     // Feed the HTML into the parser.
     $graph = $this->getRdfGraph(Url::fromRoute('<front>'));
     // Ensure that both articles are listed.
     $this->assertEqual(2, count($graph->allOfType('http://schema.org/Article')), 'Two articles found on front page.');
     // Test interaction count.
     $expected_value = array('type' => 'literal', 'value' => 'UserComments:1', 'lang' => 'en');
     $this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/interactionCount', $expected_value), "Teaser comment count was found (schema:interactionCount).");
     // Test the properties that are common between pages and articles and are
     // displayed in full and teaser mode.
     $this->assertRdfaCommonNodeProperties($graph, $this->article, "Teaser");
     // Test properties that are displayed in both teaser and full mode.
     $this->assertRdfaArticleProperties($graph, "Teaser");
     // @todo Once the image points to the original instead of the processed
     //   image, move this to testArticleProperties().
     $image_file = $this->article->get('field_image')->entity;
     $image_uri = ImageStyle::load('medium')->buildUrl($image_file->getFileUri());
     $expected_value = array('type' => 'uri', 'value' => $image_uri);
     $this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/image', $expected_value), "Teaser image was found (schema:image).");
 }
Ejemplo n.º 30
0
 /**
  * Get the values from the form and provider required for the client.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The form state from the dialog submission.
  * @param \Drupal\video_embed_field\ProviderPluginInterface $provider
  *   The provider loaded from the user input.
  *
  * @return array
  *   An array of values sent to the client for use in the WYSIWYG.
  */
 protected function getClientValues(FormStateInterface $form_state, ProviderPluginInterface $provider)
 {
     // All settings from the field formatter exist in the form and are relevant
     // for the rendering of the video.
     $video_formatter_settings = Video::defaultSettings();
     foreach ($video_formatter_settings as $key => $default) {
         $video_formatter_settings[$key] = $form_state->getValue($key);
     }
     $provider->downloadThumbnail();
     $thumbnail_preview = ImageStyle::load('video_embed_wysiwyg_preview')->buildUrl($provider->getLocalThumbnailUri());
     $thumbnail_preview_parts = parse_url($thumbnail_preview);
     return ['preview_thumbnail' => $thumbnail_preview_parts['path'] . (!empty($thumbnail_preview_parts['query']) ? '?' : '') . $thumbnail_preview_parts['query'], 'video_url' => $form_state->getValue('video_url'), 'settings' => $video_formatter_settings, 'settings_summary' => Video::mockInstance($video_formatter_settings)->settingsSummary()];
 }