/** * Implements hook_preprocess_html(). * Meta tags https://drupal.org/node/1468582#comment-5698732 */ function treetopstravel_preprocess_html(&$variables) { $meta_charset = array('#tag' => 'meta', '#attributes' => array('charset' => 'utf-8')); drupal_add_html_head($meta_charset, 'meta_charset'); $meta_x_ua_compatible = array('#tag' => 'meta', '#attributes' => array('http-equiv' => 'x-ua-compatible', 'content' => 'ie=edge, chrome=1')); drupal_add_html_head($meta_x_ua_compatible, 'meta_x_ua_compatible'); $meta_mobile_optimized = array('#tag' => 'meta', '#attributes' => array('name' => 'MobileOptimized', 'content' => 'width')); drupal_add_html_head($meta_mobile_optimized, 'meta_mobile_optimized'); $meta_handheld_friendly = array('#tag' => 'meta', '#attributes' => array('name' => 'HandheldFriendly', 'content' => 'true')); drupal_add_html_head($meta_handheld_friendly, 'meta_handheld_friendly'); $meta_viewport = array('#tag' => 'meta', '#attributes' => array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1')); drupal_add_html_head($meta_viewport, 'meta_viewport'); $meta_cleartype = array('#tag' => 'meta', '#attributes' => array('http-equiv' => 'cleartype', 'content' => 'on')); drupal_add_html_head($meta_cleartype, 'meta_cleartype'); // Use html5shiv. if (theme_get_setting('html5shim')) { $element = array('element' => array('#tag' => 'script', '#value' => '', '#attributes' => array('type' => 'text/javascript', 'src' => file_create_url(drupal_get_path('theme', 'treetopstravel') . '/js/html5shiv-printshiv.js')))); $html5shim = array('#type' => 'markup', '#markup' => "<!--[if lt IE 9]>\n" . theme('html_tag', $element) . "<![endif]-->\n"); drupal_add_html_head($html5shim, 'treetopstravel_html5shim'); } // Use Respond.js. if (theme_get_setting('respond_js')) { drupal_add_js(drupal_get_path('theme', 'treetopstravel') . '/js/respond.min.js', array('group' => JS_LIBRARY, 'weight' => -100)); } // Use normalize.css if (theme_get_setting('normalize_css')) { drupal_add_css(drupal_get_path('theme', 'treetopstravel') . '/css/normalize.css', array('group' => CSS_SYSTEM, 'weight' => -100)); } if (arg(0) == 'taxonomy' && arg(1) == 'term') { $term = taxonomy_term_load(arg(2)); $variables['classes_array'][] = 'vocabulary-' . strtolower($term->vocabulary_machine_name); } flexslider_add(); }
/** * Gets the filpath provided a file object. * * @param type $file * @return type */ private function getPath($file) { // If the url is set, then just return it. if (!empty($file->url)) { return $file->url; } // If the path is set, then just return it. if (!empty($file->path)) { // Check to see if this is a URI. if (file_valid_uri($file->path)) { return file_create_url($file->path); } else { return $file->path; } } // If the uri is set, then just return it. if (!empty($file->uri)) { if (preg_match('/^http(s)?\\:\\/\\//', $file->uri)) { return $file->uri; } else { return file_create_url($file->uri); } } // If the value is set, then just return it. if (!empty($file->value)) { return $file->value; } // If the value is input, then just return it. if (!empty($file->input)) { return $file->input; } // Return nothing. return ''; }
/** * Implements hook_preprocess_page(). */ function carbon_preprocess_page(&$variables) { $is_front = $variables['is_front']; // Adjust the html element that wraps the site name. h1 on front page, p on other pages $variables['wrapper_site_name_prefix'] = ($is_front ? '<h1' : '<p'); $variables['wrapper_site_name_prefix'] .= ' id="site-name"'; $variables['wrapper_site_name_prefix'] .= ' class="site-name'.($is_front ? ' site-name-front' : '').'"'; $variables['wrapper_site_name_prefix'] .= '>'; $variables['wrapper_site_name_suffix'] = ($is_front ? '</h1>' : '</p>'); // If the theme's info file contains the custom theme setting // default_logo_path, set the $logo variable to that path. $default_logo_path = theme_get_setting('default_logo_path'); if (!empty($default_logo_path) && theme_get_setting('default_logo')) { $variables['logo'] = file_create_url(path_to_theme() . '/' . $default_logo_path); } else { $variables['logo'] = null; } //Arrange the elements of the main content area (content and sidebars) based on the layout class $layoutClass = _carbon_get_layout(); $layout = substr(strrchr($layoutClass, '-'), 1); //Get the last bit of the layout class, the 'abc' string $contentPos = strpos($layout, 'c'); $sidebarsLeft = substr($layout,0,$contentPos); $sidebarsRight = strrev(substr($layout,($contentPos+1))); // Reverse the string so that the floats are correct. $sidebarsHidden = ''; // Create a string of sidebars that are hidden to render and then display:none if(stripos($layout, 'a') === false) { $sidebarsHidden .= 'a'; } if(stripos($layout, 'b') === false) { $sidebarsHidden .= 'b'; } $variables['sidebars']['left'] = str_split($sidebarsLeft); $variables['sidebars']['right'] = str_split($sidebarsRight); $variables['sidebars']['hidden'] = str_split($sidebarsHidden); }
/** * {@inheritdoc} */ public function render(ResultRow $values) { $value = parent::render($values); switch ($value) { case LocalTaskItemInterface::STATUS_PENDING: $label = t('Untranslated'); $icon = drupal_get_path('module', 'tmgmt') . '/icons/ready.svg'; break; case LocalTaskItemInterface::STATUS_COMPLETED: $label = t('Translated'); $icon = drupal_get_path('module', 'tmgmt') . '/icons/gray-check.svg'; break; case LocalTaskItemInterface::STATUS_REJECTED: $label = t('Rejected'); $icon = drupal_get_path('module', 'tmgmt') . '/icons/rejected.svg'; break; case LocalTaskItemInterface::STATUS_CLOSED: $label = t('Completed'); $icon = 'core/misc/icons/73b355/check.svg'; break; default: $label = t('Untranslated'); $icon = drupal_get_path('module', 'tmgmt') . '/icons/ready.svg'; } $element = ['#type' => 'inline_template', '#template' => '<img src="{{ icon }}" title="{{ label }}"><span></span></img>', '#context' => array('icon' => file_create_url($icon), 'label' => $label)]; return \Drupal::service('renderer')->render($element); }
/** * Submits form with invalid, empty, and valid OPML files. */ protected function submitImportForm() { $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); $form['files[upload]'] = $this->getInvalidOpml(); $this->drupalPostForm('admin/config/services/aggregator/add/opml', $form, t('Import')); $this->assertText(t('No new feed has been added.'), 'Attempting to upload invalid XML.'); $edit = array('remote' => file_create_url($this->getEmptyOpml())); $this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import')); $this->assertText(t('No new feed has been added.'), 'Attempting to load empty OPML from remote URL.'); $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); $this->assertEqual($before, $after, 'No feeds were added during the two last form submissions.'); db_delete('aggregator_feed')->execute(); $feeds[0] = $this->getFeedEditArray(); $feeds[1] = $this->getFeedEditArray(); $feeds[2] = $this->getFeedEditArray(); $edit = array('files[upload]' => $this->getValidOpml($feeds), 'refresh' => '900'); $this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import')); $this->assertRaw(t('A feed with the URL %url already exists.', array('%url' => $feeds[0]['url[0][value]'])), 'Verifying that a duplicate URL was identified'); $this->assertRaw(t('A feed named %title already exists.', array('%title' => $feeds[1]['title[0][value]'])), 'Verifying that a duplicate title was identified'); $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); $this->assertEqual($after, 2, 'Verifying that two distinct feeds were added.'); $feeds_from_db = db_query("SELECT title, url, refresh FROM {aggregator_feed}"); $refresh = TRUE; foreach ($feeds_from_db as $feed) { $title[$feed->url] = $feed->title; $url[$feed->title] = $feed->url; $refresh = $refresh && $feed->refresh == 900; } $this->assertEqual($title[$feeds[0]['url[0][value]']], $feeds[0]['title[0][value]'], 'First feed was added correctly.'); $this->assertEqual($url[$feeds[1]['title[0][value]']], $feeds[1]['url[0][value]'], 'Second feed was added correctly.'); $this->assertTrue($refresh, 'Refresh times are correct.'); }
function unity_lab_preprocess_paragraphs_item_pg_common_card_rollover_card(&$vars, $hook) { $backgroundImage = ''; $vars['button_text'] = 'Read Story'; if (!empty($vars['field_links'][0]['url'])) { $vars['link_url'] = $vars['field_links'][0]['url']; } else { $vars['link_url'] = "#"; } if (!empty($vars['field_links'][0]['title'])) { $vars['button_text'] = $vars['field_links'][0]['title']; } if (isset($vars['field_image'])) { $backgroundImage = $vars['field_image'][0]['uri']; $backgroundImage = file_create_url($backgroundImage); } else { $backgroundImage = file_create_url('/sites/all/libraries/unity-lab/latest/images/backgrounds/farbeyond-stripes/redSwooshes.jpg'); } if ($backgroundImage) { // $vars['css_classes'][] = 'section-background-image'; // $vars['css_classes'][] = 'overlay-black'; // $vars['css_classes'][] = 'light-theme'; drupal_add_css('#' . $vars['css_id'] . ' {background-image: url(' . $backgroundImage . ');}', array('group' => CSS_THEME, 'type' => 'inline')); } }
/** * Test a basic file upload with File (Field) Paths. */ public function testUploadFile() { $file_system = \Drupal::service('file_system'); // Create a File field with 'node/[node:nid]' as the File path and // '[node:nid].[file:ffp-extension-original]' as the File name. $field_name = Unicode::strtolower($this->randomMachineName()); $third_party_settings['filefield_paths']['file_path']['value'] = 'node/[node:nid]'; $third_party_settings['filefield_paths']['file_name']['value'] = '[node:nid].[file:ffp-extension-original]'; $this->createFileField($field_name, 'node', $this->contentType, [], [], $third_party_settings); // Create a node with a test file. /** @var \Drupal\file\Entity\File $test_file */ $test_file = $this->getTestFile('text'); $this->drupalGet("node/add/{$this->contentType}"); $edit['title[0][value]'] = $this->randomMachineName(); $edit["files[{$field_name}_0]"] = $file_system->realpath($test_file->getFileUri()); $this->drupalPostForm(NULL, $edit, t('Upload')); // Ensure that the file was put into the Temporary file location. $config = \Drupal::config('filefield_paths.settings'); $this->assertRaw(file_create_url("{$config->get('temp_location')}/{$test_file->getFilename()}"), $this->t('File has been uploaded to the temporary file location.')); // Save the node. $this->drupalPostForm(NULL, [], t('Save and publish')); // Get created Node ID. $matches = []; preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches); $nid = $matches[1]; // Ensure that the File path has been processed correctly. $this->assertRaw("{$this->publicFilesDirectory}/node/{$nid}/{$nid}.txt", $this->t('The File path has been processed correctly.')); }
function suitcase_preprocess_region(&$vars) { if ($vars['region'] == 'content' && arg(0) == 'node' && is_numeric(arg(1)) && arg(2) !== 'edit') { $node = node_load(arg(1)); if ($node->type == 'people' && !empty($node->field_people_category)) { $vars['categories'] = array(); foreach ($node->field_people_category[LANGUAGE_NONE] as $category) { $tax = taxonomy_term_load($category['tid']); array_push($vars['categories'], $tax->name); } } } else { if ($vars['region'] == 'branding') { // Prepare Logo $vars['suitcase_config_logo'] = FALSE; $logo = variable_get('suitcase_config_logo'); $vars['site_name'] = variable_get('site_name'); if ($logo) { $logo_url = file_create_url($logo['uri']); $vars['suitcase_config_logo'] = '<div class="logo-img"><a href="' . $GLOBALS['base_url'] . '" rel="home" title="' . $vars['site_name'] . '" class="active"><img src="' . $logo_url . '" alt="Go to ' . $vars['site_name'] . ' home" id="logo" /></a></div>'; } $vars['dept_url'] = variable_get('dept_url', $default = NULL); $vars['show_isu_nameplate'] = variable_get('suitcase_config_isu_nameplate_display', 1); } } }
/** * {@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; }
/** * Tests RSS enclosure formatter display for RSS feeds. */ function testFileFieldRSSContent() { $field_name = strtolower($this->randomMachineName()); $type_name = 'article'; $field_settings = array('display_field' => '1', 'display_default' => '1'); $field_settings = array('description_field' => '1'); $widget_settings = array(); $this->createFileField($field_name, 'node', $type_name, $field_settings, $field_settings, $widget_settings); // RSS display must be added manually. $this->drupalGet("admin/structure/types/manage/{$type_name}/display"); $edit = array("display_modes_custom[rss]" => '1'); $this->drupalPostForm(NULL, $edit, t('Save')); // Change the format to 'RSS enclosure'. $this->drupalGet("admin/structure/types/manage/{$type_name}/display/rss"); $edit = array("fields[{$field_name}][type]" => 'file_rss_enclosure'); $this->drupalPostForm(NULL, $edit, t('Save')); // Create a new node with a file field set. Promote to frontpage // needs to be set so this node will appear in the RSS feed. $node = $this->drupalCreateNode(array('type' => $type_name, 'promote' => 1)); $test_file = $this->getTestFile('text'); // Create a new node with the uploaded file. $nid = $this->uploadNodeFile($test_file, $field_name, $node->id()); // Get the uploaded file from the node. $node = node_load($nid, TRUE); $node_file = file_load($node->{$field_name}->target_id); // Check that the RSS enclosure appears in the RSS feed. $this->drupalGet('rss.xml'); $uploaded_filename = str_replace('public://', '', $node_file->getFileUri()); $test_element = array('key' => 'enclosure', 'value' => "", 'attributes' => array('url' => file_create_url("public://{$uploaded_filename}", array('absolute' => TRUE)), 'length' => $node_file->getSize(), 'type' => $node_file->getMimeType())); $this->assertRaw(format_xml_elements(array($test_element)), 'File field RSS enclosure is displayed when viewing the RSS feed.'); }
function getRelatedPosts($ntype, $nid) { $nids = db_query("SELECT n.nid, title FROM {node} n WHERE n.status = 1 AND n.type = :type AND n.nid <> :nid ORDER BY RAND() LIMIT 0,2", array(':type' => $ntype, ':nid' => $nid))->fetchCol(); $nodes = node_load_multiple($nids); $return_string = ''; if (!empty($nodes)) { foreach ($nodes as $node) { $field_image = field_get_items('node', $node, 'field_image_blog'); $return_string .= '<li class="item content-in col-md-6"><div class="widget-post-wrap">'; $return_string .= '<div class="thumb"><a href="' . url("node/" . $node->nid) . '">'; $return_string .= '<img src="' . file_create_url($node->field_image['und'][0]['uri']) . '" alt="' . $node->title . '">'; $return_string .= '</a></div>'; $return_string .= '<div class="article-content-wrap">'; $return_string .= '<h4 class="title"><a href="' . url("node/" . $node->nid) . '">'; $return_string .= $node->title . '</a></h4>'; $return_string .= '<div class="excerpt">' . substr($node->body['und'][0]['value'], 0, 100) . '...' . '</div>'; $return_string .= '<div class="meta-bottom">'; /* $return_string .= '<div class="post-cat"><span><i class="fa fa-folder"></i></span>'.strip_tags(render($content['field_blog_category']),'<a>').'</div>';*/ $return_string .= '<div class="post-date"><span><i class="fa fa-clock-o"></i></span>' . format_date($node->created, 'custom', 'M j,Y') . '</div>'; $return_string .= '<div class="meta-comment"><span><i class="fa fa-comments-o"></i></span><a href="' . url("node/" . $node->nid) . '">' . $node->comment_count . '</a></div>'; $return_string .= '</div></div>'; $return_string .= '<a class="bk-cover-link" href="' . url("node/" . $node->nid) . '"></a></div>'; $return_string .= '</li>'; } } return $return_string; }
/** * Add CSS information to the renderer. * * To facilitate previews over Views, CSS can now be added in a manner * that does not necessarily mean just using drupal_add_css. Therefore, * during the panel rendering process, this method can be used to add * css and make certain that ti gets to the proper location. * * The arguments should exactly match drupal_add_css(). * * @see drupal_add_css */ function add_css($filename, $type = 'module', $media = 'all', $preprocess = TRUE) { $path = file_create_path($filename); switch ($this->meta_location) { case 'standard': if ($path) { // Use CTools CSS add because it can handle temporary CSS in private // filesystem. ctools_include('css'); ctools_css_add_css($filename, $type, $media, $preprocess); } else { drupal_add_css($filename, $type, $media, $preprocess); } break; case 'inline': if ($path) { $url = file_create_url($filename); } else { $url = base_path() . $filename; } $this->prefix .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . $url . '" />'."\n"; break; } }
/** * Tests using entity fields of the file field type. */ public function testFileItem() { // Create a test entity with the $entity = entity_create('entity_test'); $entity->file_test->target_id = $this->file->id(); $entity->file_test->display = 1; $entity->file_test->description = $description = $this->randomName(); $entity->name->value = $this->randomName(); $entity->save(); $entity = entity_load('entity_test', $entity->id()); $this->assertTrue($entity->file_test instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertTrue($entity->file_test[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertEqual($entity->file_test->target_id, $this->file->id()); $this->assertEqual($entity->file_test->display, 1); $this->assertEqual($entity->file_test->description, $description); $this->assertEqual($entity->file_test->entity->getFileUri(), $this->file->getFileUri()); $this->assertEqual($entity->file_test->entity->url(), $url = file_create_url($this->file->getFileUri())); $this->assertEqual($entity->file_test->entity->id(), $this->file->id()); $this->assertEqual($entity->file_test->entity->uuid(), $this->file->uuid()); // Make sure the computed files reflects updates to the file. file_put_contents('public://example-2.txt', $this->randomName()); $file2 = entity_create('file', array('uri' => 'public://example-2.txt')); $file2->save(); $entity->file_test->target_id = $file2->id(); $this->assertEqual($entity->file_test->entity->id(), $file2->id()); $this->assertEqual($entity->file_test->entity->getFileUri(), $file2->getFileUri()); // Test the deletion of an entity having an entity reference field targeting // a non-existing entity. $file2->delete(); $entity->delete(); }
/** * Add in some variables for use in page.tpl.php * * Implements template_preprocess_page(&$variables) * * @param type &$variables */ function uw_boundless_preprocess_page(&$variables) { //hero-image front page $variables['uw_hero_image_front_path'] = theme_get_setting('uw_boundless_hero_image_front_default') ? file_create_url(theme_get_setting('uw_boundless_hero_image_front_default_path')) : file_create_url(theme_get_setting('uw_boundless_hero_image_front_path')); // hero-image other pages $variables['uw_hero_image_path'] = theme_get_setting('uw_boundless_hero_image_default') ? file_create_url(theme_get_setting('uw_boundless_hero_image_default_path')) : file_create_url(theme_get_setting('uw_boundless_hero_image_path')); // front page title color $variables['uw_front_title_color'] = theme_get_setting('uw_boundless_front_page_title_color'); $variables['uw_front_title_text_shadow'] = _uw_boundless_get_text_shadow($variables['uw_front_title_color']); // front page slant color $variables['uw_front_slant_color'] = theme_get_setting('uw_boundless_front_page_slant_color'); // front page slogan color $variables['uw_front_slogan_color'] = theme_get_setting('uw_boundless_front_page_slogan_color'); $variables['uw_front_slogan_text_shadow'] = _uw_boundless_get_text_shadow($variables['uw_front_slogan_color']); //new variable for the sidebar menu $variables['uw_sidebar_menu'] = _uw_boundless_uw_sidebar_menu(); // new variable to display copyright $variables['uw_copyright_year'] = _uw_boundless_copyrightyear(); // reset content column class from bootstrap's default col-sm-9 to col-md-8. // the column class for uw-sidebar is hard-coded in page.tpl.php if ($variables['uw_sidebar_menu'] || !empty($variables['page']['sidebar_first']) || !empty($variables['page']['sidebar_second'])) { $variables['content_column_class'] = ' class="col-md-8"'; } else { $variables['content_column_class'] = ' class="col-sm-12"'; } }
/** * {@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; }
public function viewElements(FieldItemListInterface $items, $langcode) { $elements = array(); foreach ($items as $delta => $item) { $filename = $item->entity->getFilename(); if ($item->isDisplayed() && $item->entity && strpos($filename, 'pdf') ) { $scale = $this->getSetting('scale'); $file_url = file_create_url($item->entity->getFileUri()); $html = array( '#type' => 'html_tag', '#tag' => 'div', //'#value' => TODO, '#attributes' => array( 'class' => array('pdf-pages'), 'id' => array('pdf-pages-' . $delta), 'file' => array($file_url), 'scale' => array($scale) ), ); $elements[$delta] = array( '#markup' => \Drupal::service('renderer')->render($html), ); } } $elements['#attached']['library'][] = 'pdf/drupal.pdf'; $elements['#attached']['drupalSettings'] = array( 'pdf' => array( 'workerSrc' => 'https://mozilla.github.io/pdf.js/build/pdf.worker.js', ), ); return $elements; }
/** * Implements hook_preprocess_html(). * Meta tags https://drupal.org/node/1468582#comment-5698732 */ function importacionesgm_preprocess_html(&$variables) { $meta_charset = array('#tag' => 'meta', '#attributes' => array('charset' => 'utf-8')); drupal_add_html_head($meta_charset, 'meta_charset'); $meta_x_ua_compatible = array('#tag' => 'meta', '#attributes' => array('http-equiv' => 'x-ua-compatible', 'content' => 'ie=edge, chrome=1')); drupal_add_html_head($meta_x_ua_compatible, 'meta_x_ua_compatible'); $meta_mobile_optimized = array('#tag' => 'meta', '#attributes' => array('name' => 'MobileOptimized', 'content' => 'width')); drupal_add_html_head($meta_mobile_optimized, 'meta_mobile_optimized'); $meta_handheld_friendly = array('#tag' => 'meta', '#attributes' => array('name' => 'HandheldFriendly', 'content' => 'true')); drupal_add_html_head($meta_handheld_friendly, 'meta_handheld_friendly'); $meta_viewport = array('#tag' => 'meta', '#attributes' => array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1')); drupal_add_html_head($meta_viewport, 'meta_viewport'); $meta_cleartype = array('#tag' => 'meta', '#attributes' => array('http-equiv' => 'cleartype', 'content' => 'on')); drupal_add_html_head($meta_cleartype, 'meta_cleartype'); // Use html5shiv. if (theme_get_setting('html5shim')) { $element = array('element' => array('#tag' => 'script', '#value' => '', '#attributes' => array('type' => 'text/javascript', 'src' => file_create_url(drupal_get_path('theme', 'importacionesgm') . '/js/html5shiv-printshiv.js')))); $html5shim = array('#type' => 'markup', '#markup' => "<!--[if lt IE 9]>\n" . theme('html_tag', $element) . "<![endif]-->\n"); drupal_add_html_head($html5shim, 'sonambulo_html5shim'); } // Use Respond.js. if (theme_get_setting('respond_js')) { drupal_add_js(drupal_get_path('theme', 'importacionesgm') . '/js/respond.min.js', array('group' => JS_LIBRARY, 'weight' => -100)); } // Use normalize.css if (theme_get_setting('normalize_css')) { drupal_add_css(drupal_get_path('theme', 'importacionesgm') . '/css/normalize.css', array('group' => CSS_SYSTEM, 'weight' => -100)); } }
/** * Tests file entity denormalization. */ public function testFileDenormalize() { $file_params = array('filename' => 'test_1.txt', 'uri' => 'public://test_1.txt', 'filemime' => 'text/plain', 'status' => FILE_STATUS_PERMANENT); // Create a new file entity. $file = entity_create('file', $file_params); file_put_contents($file->getFileUri(), 'hello world'); $file->save(); $serializer = \Drupal::service('serializer'); $normalized_data = $serializer->normalize($file, 'hal_json'); $denormalized = $serializer->denormalize($normalized_data, 'Drupal\\file\\Entity\\File', 'hal_json'); $this->assertTrue($denormalized instanceof File, 'A File instance was created.'); $this->assertIdentical('temporary://' . $file->getFilename(), $denormalized->getFileUri(), 'The expected file URI was found.'); $this->assertTrue(file_exists($denormalized->getFileUri()), 'The temporary file was found.'); $this->assertIdentical($file->uuid(), $denormalized->uuid(), 'The expected UUID was found'); $this->assertIdentical($file->getMimeType(), $denormalized->getMimeType(), 'The expected mime type was found.'); $this->assertIdentical($file->getFilename(), $denormalized->getFilename(), 'The expected filename was found.'); $this->assertTrue($denormalized->isPermanent(), 'The file has a permanent status.'); // Try to denormalize with the file uri only. $file_name = 'test_2.txt'; $file_path = 'public://' . $file_name; file_put_contents($file_path, 'hello world'); $file_uri = file_create_url($file_path); $data = array('uri' => array(array('value' => $file_uri))); $denormalized = $serializer->denormalize($data, 'Drupal\\file\\Entity\\File', 'hal_json'); $this->assertIdentical('temporary://' . $file_name, $denormalized->getFileUri(), 'The expected file URI was found.'); $this->assertTrue(file_exists($denormalized->getFileUri()), 'The temporary file was found.'); $this->assertIdentical('text/plain', $denormalized->getMimeType(), 'The expected mime type was found.'); $this->assertIdentical($file_name, $denormalized->getFilename(), 'The expected filename was found.'); $this->assertFalse($denormalized->isPermanent(), 'The file has a permanent status.'); }
/** * Tests file access for file uploaded to a private node. */ function testPrivateFile() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, 'node', $type_name, array('uri_scheme' => 'private')); // Create a field with no view access. See // field_test_entity_field_access(). $no_access_field_name = 'field_no_view_access'; $this->createFileField($no_access_field_name, 'node', $type_name, array('uri_scheme' => 'private')); $test_file = $this->getTestFile('text'); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); $node_file = file_load($node->{$field_name}->target_id); // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.'); $this->drupalLogOut(); $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(403, 'Confirmed that access is denied for the file without the needed permission.'); // Test with the field that should deny access through field access. $this->drupalLogin($this->admin_user); $nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); $node_file = file_load($node->{$no_access_field_name}->target_id); // Ensure the file cannot be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(403, 'Confirmed that access is denied for the file without view field access permission.'); }
/** * Get path to WSDL file that contains soap:address location attribute corrected according to request made by client * Also make cached copies of modified WSDL file. * * @param string $service_url * URL of SOAP service * @return string * Absolute or relative path to WSDL file. */ function get_wsdl_path($service_url) { global $drupal_url; $source_wsdl_path = drupal_get_path('module', 'mpay_integration') . '/soap/mpay-server.wsdl'; //Fallback to default WSDL file if files directory is not properly configured $wsdl_path = $source_wsdl_path; //check for wsdl file with such suffix (hashed suffix) $try_mpay_server_xsd_path = 'public://' . MPAY_SERVER_WSDL_CACHE_PREFIX . md5($service_url) . 'mpay-server.xsd'; $try_mpay_server1_xsd_path = 'public://' . MPAY_SERVER_WSDL_CACHE_PREFIX . md5($service_url) . 'mpay-server1.xsd'; $try_wsdl_path = 'public://' . MPAY_SERVER_WSDL_CACHE_PREFIX . md5($service_url) . '.wsdl'; if ($try_wsdl_path) { $wsdl_path = $try_wsdl_path; // if missing: compose new url with path = soap/?wsdl if (!is_readable($wsdl_path)) { // xml load, change, save $wsdl = simplexml_load_file($source_wsdl_path); $namespaces = $wsdl->getNamespaces(TRUE); $wsdl->children($namespaces["wsdl"])->types->children($namespaces["xsd"])->schema->import[0]->attributes()->schemaLocation = file_create_url($try_mpay_server1_xsd_path); $wsdl->children($namespaces["wsdl"])->types->children($namespaces["xsd"])->schema->import[1]->attributes()->schemaLocation = file_create_url($try_mpay_server_xsd_path); $wsdl->children($namespaces["wsdl"])->service->port->children($namespaces["soap"])->address->attributes()->location = $service_url; $wsdl->asXML($wsdl_path); // Load xsd Files and save in right place $source_wsdl_path = drupal_get_path('module', 'mpay_integration') . '/soap/mpay-server1.xsd'; $wsdl = simplexml_load_file($source_wsdl_path); $namespaces = $wsdl->getNamespaces(TRUE); $wsdl->children($namespaces["xs"])->import->attributes()->schemaLocation = file_create_url($try_mpay_server1_xsd_path); $wsdl->asXML($try_mpay_server1_xsd_path); $source_wsdl_path = drupal_get_path('module', 'mpay_integration') . '/soap/mpay-server.xsd'; $wsdl = simplexml_load_file($source_wsdl_path); $wsdl->asXML($try_mpay_server_xsd_path); } } return $wsdl_path; }
/** * Returns HTML for a textfield form element. * * @param array $variables * An associative array containing: * - element: An associative array containing the properties of the element. * Properties used: #title, #value, #description, #size, #maxlength, * #required, #attributes, #autocomplete_path. * * @return string * The constructed HTML. * * @see theme_textfield() * * @ingroup theme_functions */ function bootstrap_textfield($variables) { $element = $variables['element']; $element['#attributes']['type'] = 'text'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); _form_set_class($element, array('form-text')); $output = '<input' . drupal_attributes($element['#attributes']) . ' />'; $extra = ''; if ($element['#autocomplete_path'] && !empty($element['#autocomplete_input'])) { drupal_add_library('system', 'drupal.autocomplete'); $element['#attributes']['class'][] = 'form-autocomplete'; $attributes = array(); $attributes['type'] = 'hidden'; $attributes['id'] = $element['#autocomplete_input']['#id']; $attributes['value'] = $element['#autocomplete_input']['#url_value']; $attributes['disabled'] = 'disabled'; $attributes['class'][] = 'autocomplete'; // Uses icon for autocomplete "throbber". if ($icon = _bootstrap_icon('refresh')) { $output = '<div class="input-group">' . $output . '<span class="input-group-addon">' . $icon . '</span></div>'; } else { $output = '<div class="input-group">' . $output . '<span class="input-group-addon">'; // The throbber's background image must be set here because sites may not // be at the root of the domain (ie: /) and this value cannot be set via // CSS. $output .= '<span class="autocomplete-throbber" style="background-image:url(' . file_create_url('misc/throbber.gif') . ')"></span>'; $output .= '</span></div>'; } $extra = '<input' . drupal_attributes($attributes) . ' />'; } return $output . $extra; }
/** * Tests file field formatter Entity Embed Display plugins. */ public function testFileFieldFormatter() { // Ensure that file field formatters are available as plugins. $this->assertAvailableDisplayPlugins($this->file, ['entity_reference:entity_reference_label', 'entity_reference:entity_reference_entity_id', 'file:file_default', 'file:file_table', 'file:file_url_plain']); // Ensure that correct form attributes are returned for the file field // formatter plugins. $form = array(); $form_state = new FormState(); $plugins = array('file:file_table', 'file:file_default', 'file:file_url_plain'); // Ensure that description field is available for all the 'file' plugins. foreach ($plugins as $plugin) { $display = $this->displayPluginManager()->createInstance($plugin, array()); $display->setContextValue('entity', $this->file); $conf_form = $display->buildConfigurationForm($form, $form_state); $this->assertIdentical(array_keys($conf_form), array('description')); $this->assertIdentical($conf_form['description']['#type'], 'textfield'); $this->assertIdentical((string) $conf_form['description']['#title'], 'Description'); } // Test entity embed using 'Generic file' Entity Embed Display plugin. $embed_settings = array('description' => "This is sample description"); $content = '<drupal-entity data-entity-type="file" data-entity-uuid="' . $this->file->uuid() . '" data-entity-embed-display="file:file_default" data-entity-embed-settings=\'' . Json::encode($embed_settings) . '\'>This placeholder should not be rendered.</drupal-entity>'; $settings = array(); $settings['type'] = 'page'; $settings['title'] = 'Test entity embed with file:file_default'; $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); $node = $this->drupalCreateNode($settings); $this->drupalGet('node/' . $node->id()); $this->assertText($embed_settings['description'], 'Description of the embedded file exists in page.'); $this->assertNoText(strip_tags($content), 'Placeholder does not appears in the output when embed is successful.'); $this->assertLinkByHref(file_create_url($this->file->getFileUri()), 0, 'Link to the embedded file exists.'); }
/** * Tests RSS enclosure formatter display for RSS feeds. */ function testFileFieldRSSContent() { $node_storage = $this->container->get('entity.manager')->getStorage('node'); $field_name = strtolower($this->randomMachineName()); $type_name = 'article'; $this->createFileField($field_name, 'node', $type_name); // RSS display must be added manually. $this->drupalGet("admin/structure/types/manage/{$type_name}/display"); $edit = array("display_modes_custom[rss]" => '1'); $this->drupalPostForm(NULL, $edit, t('Save')); // Change the format to 'RSS enclosure'. $this->drupalGet("admin/structure/types/manage/{$type_name}/display/rss"); $edit = array("fields[{$field_name}][type]" => 'file_rss_enclosure'); $this->drupalPostForm(NULL, $edit, t('Save')); // Create a new node with a file field set. Promote to frontpage // needs to be set so this node will appear in the RSS feed. $node = $this->drupalCreateNode(array('type' => $type_name, 'promote' => 1)); $test_file = $this->getTestFile('text'); // Create a new node with the uploaded file. $nid = $this->uploadNodeFile($test_file, $field_name, $node->id()); // Get the uploaded file from the node. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); // Check that the RSS enclosure appears in the RSS feed. $this->drupalGet('rss.xml'); $uploaded_filename = str_replace('public://', '', $node_file->getFileUri()); $test_element = sprintf('<enclosure url="%s" length="%s" type="%s" />', file_create_url("public://{$uploaded_filename}", array('absolute' => TRUE)), $node_file->getSize(), $node_file->getMimeType()); $this->assertRaw($test_element, 'File field RSS enclosure is displayed when viewing the RSS feed.'); }
/** * Overrides \RestfulEntityBase::viewEntity(). * * Always return the current user. */ public function viewEntity($entity_id) { $account = $this->getAccount(); $me = parent::viewEntity($account->uid); $me['picture'] = $account->picture ? file_create_url($account->picture->uri) : file_create_url(file_load(variable_get('default_user_picture_fid'))->uri); return $me; }
public function testTaxonomyImageAccess() { $user = $this->drupalCreateUser(array('administer site configuration', 'administer taxonomy', 'access user profiles')); $this->drupalLogin($user); // Create a term and upload the image. $files = $this->drupalGetTestFiles('image'); $image = array_pop($files); $edit['name[0][value]'] = $this->randomMachineName(); $edit['files[field_test_0]'] = drupal_realpath($image->uri); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save')); $this->drupalPostForm(NULL, ['field_test[0][alt]' => $this->randomMachineName()], t('Save')); $terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $edit['name[0][value]'])); $term = reset($terms); $this->assertText(t('Created new term @name.', array('@name' => $term->getName()))); // Create a user that should have access to the file and one that doesn't. $access_user = $this->drupalCreateUser(array('access content')); $no_access_user = $this->drupalCreateUser(); $image = File::load($term->field_test->target_id); $this->drupalLogin($access_user); $this->drupalGet(file_create_url($image->getFileUri())); $this->assertResponse(200, 'Private image on term is accessible with right permission'); $this->drupalLogin($no_access_user); $this->drupalGet(file_create_url($image->getFileUri())); $this->assertResponse(403, 'Private image on term not accessible without right permission'); }
/** * Implements hook_preprocess_page(). */ function eu_projects_theme_preprocess_page(&$vars, $hook) { $path_alias = drupal_get_path_alias(); // Webtools. $inline_script = '<script defer src="//europa.eu/webtools/load.js" type="text/javascript"></script>'; $element = array('#type' => 'markup', '#markup' => $inline_script); drupal_add_html_head($element, 'webtools'); // Apple-touch-icon-precomposed. $apple_touch_icon_precomposed = array('#tag' => 'link', '#attributes' => array('href' => file_create_url(path_to_theme() . '/images/apple-touch-icon.png'), 'rel' => 'apple-touch-icon-precomposed')); drupal_add_html_head($apple_touch_icon_precomposed, 'apple-touch-icon-precomposed'); // Apple-touch-icon. $apple_touch_icon = array('#tag' => 'link', '#attributes' => array('href' => file_create_url(path_to_theme() . '/images/apple-touch-icon.png'), 'rel' => 'icon')); drupal_add_html_head($apple_touch_icon, 'apple-touch-icon'); // Apple-mobile-web-app-capable. $apple_mobile_web_app_capable = array('#tag' => 'meta', '#attributes' => array('name' => 'apple-mobile-web-app-capable', 'content' => 'yes')); drupal_add_html_head($apple_mobile_web_app_capable, 'apple-mobile-web-app-capable'); // Application-name. $application_name = array('#tag' => 'meta', '#attributes' => array('name' => 'application-name', 'content' => t('EU Results'))); drupal_add_html_head($application_name, 'application-name'); // Apple-mobile-web-app-title. $apple_mobile_web_app_title = array('#tag' => 'meta', '#attributes' => array('name' => 'apple-mobile-web-app-title', 'content' => t('EU Results'))); drupal_add_html_head($apple_mobile_web_app_title, 'apple-mobile-web-app-title'); // Apple-touch-startup-image-ec. $apple_touch_startup_image_ec = array('#tag' => 'meta', '#attributes' => array('rel' => 'apple-touch-startup-image-ec', 'href' => file_create_url(path_to_theme() . '/images/startup-image.png'))); drupal_add_html_head($apple_touch_startup_image_ec, 'apple-touch-startup-image-ec'); // Preload geojson for map if ($path_alias == 'search-projects') { $path = explode('?', request_uri()); $var = isset($path[1]) ? '?' . $path[1] : ''; $preload_geojson = array('#tag' => 'link', '#attributes' => array('rel' => 'prefetch', 'href' => $GLOBALS['base_url'] . '/projects-geojson_' . $GLOBALS['language']->language . $var)); drupal_add_html_head($preload_geojson, 'preload_geojson'); } }
/** * Add link to view full-sized image in colorbox and add caption */ function gettysw_preprocess_field(&$vars, $hook) { foreach ($vars['element']['#items'] as $delta => $item) { if (!empty($vars['element'][$delta])) { if (module_exists('image_field_caption') && isset($item['image_field_caption'])) { $vars['items'][$delta]['caption'] = check_markup($item['image_field_caption']['value'], $item['image_field_caption']['format']); } if ($vars['element']['#field_name'] == 'field_image' && isset($item['uri']) && module_exists('colorbox') && empty($vars['element']['#object']->is_export)) { $vars['items'][$delta]['colorbox_link'] = '<a class="colorbox" href="' . file_create_url($item['uri']) . '">Expand Image</a>'; } if ($vars['element']['#field_name'] == 'field_image_reference_info' && $vars['element']['#view_mode'] == 'full') { drupal_add_css(drupal_get_path('module', 'lighttable') . '/lighttable.css'); $vars['content_attributes_array'] = array('id' => 'lighttable'); foreach ($vars['items'] as $delta => $item) { $fc_item = reset($vars['items'][$delta]['entity']['field_collection_item']); $image_entity = $fc_item['#entity']->field_image_reference[LANGUAGE_NONE][0]['entity']; $file_nodes = file_usage_list($image_entity); $image_node = node_load(key($file_nodes['file']['node'])); $vars['items'][$delta]['entity']['field_collection_item']['title'] = array('#markup' => '<span class="field-title">' . $image_node->title . '</span>', '#weight' => -1); $left = $fc_item['#entity']->field_x_pos[LANGUAGE_NONE][0]['value']; $top = $fc_item['#entity']->field_y_pos[LANGUAGE_NONE][0]['value']; $width = $fc_item['#entity']->field_width[LANGUAGE_NONE][0]['value']; $height = $fc_item['#entity']->field_height[LANGUAGE_NONE][0]['value']; $vars['items'][$delta]['#attributes']['style'] = "position: absolute; top: {$top}px; left: {$left}px; width: {$width}px; height: {$height}px;"; $vars['items'][$delta]['#attributes']['class'][] = 'lighttable-image-container'; } } } } }
function cstark_preprocess_node(&$variables) { if (user_access('administer nodes')) { $variables['edit_link'] = l(t('Edit'), 'node/' . $variables['nid'] . '/edit'); if ($variables['type'] == 'painting') { $title = $variables['promote'] ? t('Remove from front page') : t('Add to front page'); $variables['set_as_main_link'] = l($title, 'set-as-main/' . $variables['nid']); // Facebook share. $url = url('node/' . $variables['nid'], array('absolute' => TRUE)); $variables['share_link'] = l(t('Share'), "http://www.facebook.com/sharer.php?u={$url}", array('attributes' => array('class' => array('facebook')))); } } if ($variables['type'] == 'painting') { $wrapper = entity_metadata_wrapper('node', $variables['nid']); if ($image = $wrapper->field_image->value()) { $element = array('#tag' => 'meta', '#attributes' => array('property' => 'og:image', 'content' => file_create_url($image['uri']))); drupal_add_html_head($element, 'cstark_painting_image'); $element = array('#tag' => 'meta', '#attributes' => array('property' => 'og:title', 'content' => $wrapper->label())); drupal_add_html_head($element, 'cstark_painting_title'); } } if ($variables['type'] == 'painting' && !drupal_is_front_page()) { $variables['pager'] = shapira_get_painting_pager($variables['nid']); } if ($variables['type'] != 'news') { $variables['hide_title'] = true; } if ($variables['type'] == 'painting') { if ($variables['field_image']) { $info = image_get_info(image_style_path('painting', $variables['field_image'][0]['uri'])); $variables['node_width'] = $info['width']; } } }
/** * Invokes system_retrieve_file() in several scenarios. */ function testFileRetrieving() { // Test 404 handling by trying to fetch a randomly named file. drupal_mkdir($sourcedir = 'public://' . $this->randomMachineName()); $filename = 'Файл для тестирования ' . $this->randomMachineName(); $url = file_create_url($sourcedir . '/' . $filename); $retrieved_file = system_retrieve_file($url); $this->assertFalse($retrieved_file, 'Non-existent file not fetched.'); // Actually create that file, download it via HTTP and test the returned path. file_put_contents($sourcedir . '/' . $filename, 'testing'); $retrieved_file = system_retrieve_file($url); // URLs could not contains characters outside the ASCII set so $filename // has to be encoded. $encoded_filename = rawurlencode($filename); $this->assertEqual($retrieved_file, 'public://' . $encoded_filename, 'Sane path for downloaded file returned (public:// scheme).'); $this->assertTrue(is_file($retrieved_file), 'Downloaded file does exist (public:// scheme).'); $this->assertEqual(filesize($retrieved_file), 7, 'File size of downloaded file is correct (public:// scheme).'); file_unmanaged_delete($retrieved_file); // Test downloading file to a different location. drupal_mkdir($targetdir = 'temporary://' . $this->randomMachineName()); $retrieved_file = system_retrieve_file($url, $targetdir); $this->assertEqual($retrieved_file, "{$targetdir}/{$encoded_filename}", 'Sane path for downloaded file returned (temporary:// scheme).'); $this->assertTrue(is_file($retrieved_file), 'Downloaded file does exist (temporary:// scheme).'); $this->assertEqual(filesize($retrieved_file), 7, 'File size of downloaded file is correct (temporary:// scheme).'); file_unmanaged_delete($retrieved_file); file_unmanaged_delete_recursive($sourcedir); file_unmanaged_delete_recursive($targetdir); }
protected function unhandleSingleValue($entity_type, $field_type, $field_name, &$value) { if (!is_array($value)) { return; } if (!array_key_exists('files', $value)) { return; } if (!array_key_exists('contents', $value)) { return; } $find = array(); $replace = array(); foreach ($value['files'] as $original_url => $file) { try { $file_entity = self::entityFromReferenceDefinition($file); if (!$file_entity) { continue; } $find[] = $original_url; $replace[] = file_create_url($file_entity->definition->uri); } catch (InvalidReferenceDefinitionException $ex) { drupal_set_message(t('Tried to import textarea-referenced file: @uuid, but it did not exist. Ignoring.', array('@uuid' => $file['uuid'])), 'warning'); $find[] = $original_url; $replace[] = $original_url; } } $this->postUnhandleResults($value, $find, $replace, 'files'); }