Example #1
0
 /**
  * Test directory handling functions.
  */
 function testFileCheckDirectoryHandling()
 {
     // A directory to operate on.
     $directory = file_default_scheme() . '://' . $this->randomMachineName() . '/' . $this->randomMachineName();
     $this->assertFalse(is_dir($directory), 'Directory does not exist prior to testing.');
     // Non-existent directory.
     $this->assertFalse(file_prepare_directory($directory, 0), 'Error reported for non-existing directory.', 'File');
     // Make a directory.
     $this->assertTrue(file_prepare_directory($directory, FILE_CREATE_DIRECTORY), 'No error reported when creating a new directory.', 'File');
     // Make sure directory actually exists.
     $this->assertTrue(is_dir($directory), 'Directory actually exists.', 'File');
     if (substr(PHP_OS, 0, 3) != 'WIN') {
         // PHP on Windows doesn't support any kind of useful read-only mode for
         // directories. When executing a chmod() on a directory, PHP only sets the
         // read-only flag, which doesn't prevent files to actually be written
         // in the directory on any recent version of Windows.
         // Make directory read only.
         @drupal_chmod($directory, 0444);
         $this->assertFalse(file_prepare_directory($directory, 0), 'Error reported for a non-writeable directory.', 'File');
         // Test directory permission modification.
         $this->setSetting('file_chmod_directory', 0777);
         $this->assertTrue(file_prepare_directory($directory, FILE_MODIFY_PERMISSIONS), 'No error reported when making directory writeable.', 'File');
     }
     // Test that the directory has the correct permissions.
     $this->assertDirectoryPermissions($directory, 0777, 'file_chmod_directory setting is respected.');
     // Remove .htaccess file to then test that it gets re-created.
     @drupal_unlink(file_default_scheme() . '://.htaccess');
     $this->assertFalse(is_file(file_default_scheme() . '://.htaccess'), 'Successfully removed the .htaccess file in the files directory.', 'File');
     file_ensure_htaccess();
     $this->assertTrue(is_file(file_default_scheme() . '://.htaccess'), 'Successfully re-created the .htaccess file in the files directory.', 'File');
     // Verify contents of .htaccess file.
     $file = file_get_contents(file_default_scheme() . '://.htaccess');
     $this->assertEqual($file, FileStorage::htaccessLines(FALSE), 'The .htaccess file contains the proper content.', 'File');
 }
 /**
  * Constructs a DataProviderFile object.
  */
 public function __construct(RequestInterface $request, ResourceFieldCollectionInterface $field_definitions, $account, $plugin_id, $resource_path, array $options, $langcode = NULL)
 {
     parent::__construct($request, $field_definitions, $account, $plugin_id, $resource_path, $options, $langcode);
     $file_options = empty($this->options['options']) ? array() : $this->options['options'];
     $default_values = array('validators' => array('file_validate_extensions' => array(), 'file_validate_size' => array()), 'scheme' => file_default_scheme(), 'replace' => FILE_EXISTS_RENAME);
     $this->options['options'] = drupal_array_merge_deep($default_values, $file_options);
 }
Example #3
0
function puzzle_form_system_theme_settings_alter(&$form, $form_state)
{
    $form['layout_style'] = array('#type' => 'select', '#title' => t('Layout Style'), '#default_value' => theme_get_setting('layout_style'), '#options' => array('wide' => t('Wide'), 'boxed' => t('Boxed')));
    $form['main_color'] = array('#type' => 'select', '#title' => t('Main Color'), '#default_value' => theme_get_setting('main_color'), '#options' => array('corporate' => 'corporate', 'cyan' => 'cyan', 'medical' => 'medical', 'restaurant' => 'restaurant', 'portfolio' => 'portfolio', 'orange' => 'orange', 'tangerine' => 'tangerine', 'gold' => 'gold'));
    $form['background_color'] = array('#type' => 'select', '#title' => t('Background'), '#default_value' => theme_get_setting('background_color'), '#options' => background_color());
    $form['background_image'] = array('#type' => 'managed_file', '#title' => t('Background Image'), '#default_value' => theme_get_setting('background_image'), '#upload_location' => file_default_scheme() . '://theme_background', '#upload_validators' => array('file_validate_extensions' => array('gif png jpg jpeg')));
    $form['header_top_padding'] = array('#type' => 'textfield', '#title' => t('HEader Top Padding'), '#default_value' => theme_get_setting('header_top_padding'));
}
Example #4
0
 /**
  * Get the path for css file.
  *
  * @param bool $dironly
  *   TRUE if wants only the dir, FALSE for the full path + file.
  *
  * @return string
  *   Full path to css file.
  */
 public static function languageCssPath($dironly = FALSE)
 {
     $directory = file_default_scheme() . '://geshi';
     if (!$dironly) {
         $directory .= '/geshifilter-languages.css';
     }
     return $directory;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $id = $this->entity->id;
     $file_name = file_default_scheme() . "://js_injector/{$id}.js";
     file_unmanaged_delete_recursive($file_name);
     $this->entity->delete();
     drupal_set_message($this->t('Js Injector deleted @label.', ['@label' => $this->entity->label()]));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
 /**
  * Delete a normal file.
  */
 function testSingleFile()
 {
     // Create a file for testing
     $filepath = file_default_scheme() . '://' . $this->randomMachineName();
     file_put_contents($filepath, '');
     // Delete the file.
     $this->assertTrue(file_unmanaged_delete_recursive($filepath), 'Function reported success.');
     $this->assertFalse(file_exists($filepath), 'Test file has been deleted.');
 }
Example #7
0
 function testPathologic()
 {
     global $script_path;
     // Start by testing our function to build protocol-relative URLs
     $this->assertEqual(_pathologic_url_to_protocol_relative('http://example.com/foo/bar'), '//example.com/foo/bar', t('Protocol-relative URL creation with http:// URL'));
     $this->assertEqual(_pathologic_url_to_protocol_relative('https://example.org/baz'), '//example.org/baz', t('Protocol-relative URL creation with https:// URL'));
     // Build some paths to check against
     $test_paths = array('foo' => array('path' => 'foo', 'opts' => array()), 'foo/bar' => array('path' => 'foo/bar', 'opts' => array()), 'foo/bar?baz' => array('path' => 'foo/bar', 'opts' => array('query' => array('baz' => NULL))), 'foo/bar?baz=qux' => array('path' => 'foo/bar', 'opts' => array('query' => array('baz' => 'qux'))), 'foo/bar#baz' => array('path' => 'foo/bar', 'opts' => array('fragment' => 'baz')), 'foo/bar?baz=qux&amp;quux=quuux#quuuux' => array('path' => 'foo/bar', 'opts' => array('query' => array('baz' => 'qux', 'quux' => 'quuux'), 'fragment' => 'quuuux')), 'foo%20bar?baz=qux%26quux' => array('path' => 'foo bar', 'opts' => array('query' => array('baz' => 'qux&quux'))), '/' => array('path' => '<front>', 'opts' => array()));
     foreach (array('full', 'proto-rel', 'path') as $protocol_style) {
         $format_id = _pathologic_build_format(['settings_source' => 'local', 'local_settings' => ['protocol_style' => $protocol_style]]);
         $paths = array();
         foreach ($test_paths as $path => $args) {
             $args['opts']['absolute'] = $protocol_style !== 'path';
             $paths[$path] = _pathologic_content_url($args['path'], $args['opts']);
             if ($protocol_style === 'proto-rel') {
                 $paths[$path] = _pathologic_url_to_protocol_relative($paths[$path]);
             }
         }
         $t10ns = array('@clean' => empty($script_path) ? t('Yes') : t('No'), '@ps' => $protocol_style);
         $this->assertEqual(check_markup('<a href="foo"><img src="foo/bar" /></a>', $format_id), '<a href="' . $paths['foo'] . '"><img src="' . $paths['foo/bar'] . '" /></a>', t('Simple paths. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="index.php?q=foo"></a><a href="index.php?q=foo/bar&baz=qux"></a>', $format_id), '<a href="' . $paths['foo'] . '"></a><a href="' . $paths['foo/bar?baz=qux'] . '"></a>', t('D7 and earlier-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="index.php/foo"></a><a href="index.php/foo/bar?baz=qux"></a>', $format_id), '<a href="' . $paths['foo'] . '"></a><a href="' . $paths['foo/bar?baz=qux'] . '"></a>', t('D8-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<form action="foo/bar?baz"><IMG LONGDESC="foo/bar?baz=qux" /></a>', $format_id), '<form action="' . $paths['foo/bar?baz'] . '"><IMG LONGDESC="' . $paths['foo/bar?baz=qux'] . '" /></a>', t('Paths with query string. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="foo/bar#baz">', $format_id), '<a href="' . $paths['foo/bar#baz'] . '">', t('Path with fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="#foo">', $format_id), '<a href="#foo">', t('Fragment-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         // @see https://drupal.org/node/2208223
         $this->assertEqual(check_markup('<a href="#">', $format_id), '<a href="#">', t('Hash-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="foo/bar?baz=qux&amp;quux=quuux#quuuux">', $format_id), '<a href="' . $paths['foo/bar?baz=qux&amp;quux=quuux#quuuux'] . '">', t('Path with query string and fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="foo%20bar?baz=qux%26quux">', $format_id), '<a href="' . $paths['foo%20bar?baz=qux%26quux'] . '">', t('Path with URL encoded parts. Clean URLs: @clean; protocol style: @ps.', $t10ns));
         $this->assertEqual(check_markup('<a href="/"></a>', $format_id), '<a href="' . $paths['/'] . '"></a>', t('Path with just slash. Clean URLs: @clean; protocol style: @ps', $t10ns));
     }
     global $base_path;
     $this->assertEqual(check_markup('<a href="' . $base_path . 'foo">bar</a>', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => FALSE)) . '">bar</a>', t('Paths beginning with $base_path (like WYSIWYG editors like to make)'));
     global $base_url;
     $this->assertEqual(check_markup('<a href="' . $base_url . '/foo">bar</a>', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => FALSE)) . '">bar</a>', t('Paths beginning with $base_url'));
     // @see http://drupal.org/node/1617944
     $this->assertEqual(check_markup('<a href="//example.com/foo">bar</a>', $format_id), '<a href="//example.com/foo">bar</a>', t('Off-site schemeless URLs (//example.com/foo) ignored'));
     // Test internal: and all base paths
     $format_id = _pathologic_build_format(['settings_source' => 'local', 'local_settings' => ['local_paths' => "http://example.com/qux\nhttp://example.org\n/bananas", 'protocol_style' => 'full']]);
     // @see https://drupal.org/node/2030789
     $this->assertEqual(check_markup('<a href="//example.org/foo">bar</a>', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => TRUE)) . '">bar</a>', t('On-site schemeless URLs processed'));
     $this->assertEqual(check_markup('<a href="internal:foo">', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => TRUE)) . '">', t('Path Filter compatibility (internal:)'));
     $this->assertEqual(check_markup('<a href="files:image.jpeg">look</a>', $format_id), '<a href="' . _pathologic_content_url(file_create_url(file_default_scheme() . '://image.jpeg'), array('absolute' => TRUE)) . '">look</a>', t('Path Filter compatibility (files:)'));
     $this->assertEqual(check_markup('<a href="http://example.com/qux/foo"><img src="http://example.org/bar.jpeg" longdesc="/bananas/baz" /></a>', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => TRUE)) . '"><img src="' . _pathologic_content_url('bar.jpeg', array('absolute' => TRUE)) . '" longdesc="' . _pathologic_content_url('baz', array('absolute' => TRUE)) . '" /></a>', t('"All base paths for this site" functionality'));
     $this->assertEqual(check_markup('<a href="webcal:foo">bar</a>', $format_id), '<a href="webcal:foo">bar</a>', t('URLs with likely protocols are ignored'));
     // Test hook_pathologic_alter() implementation.
     $this->assertEqual(check_markup('<a href="foo?test=add_foo_qpart">', $format_id), '<a href="' . _pathologic_content_url('foo', array('absolute' => TRUE, 'query' => array('test' => 'add_foo_qpart', 'foo' => 'bar'))) . '">', t('hook_pathologic_alter(): Alter $url_params'));
     $this->assertEqual(check_markup('<a href="bar?test=use_original">', $format_id), '<a href="bar?test=use_original">', t('hook_pathologic_alter(): Passthrough with use_original option'));
     // Test paths to existing files when clean URLs are disabled.
     // @see http://drupal.org/node/1672430
     $script_path = '';
     $filtered_tag = check_markup('<img src="misc/druplicon.png" />', $format_id);
     $this->assertTrue(strpos($filtered_tag, 'q=') === FALSE, t('Paths to files don\'t have ?q= when clean URLs are off'));
     $format_id = _pathologic_build_format(['settings_source' => 'global', 'local_settings' => ['protocol_style' => 'rel']]);
     $this->config('pathologic.settings')->set('protocol_style', 'proto-rel')->set('local_paths', 'http://example.com/')->save();
     $this->assertEqual(check_markup('<img src="http://example.com/foo.jpeg" />', $format_id), '<img src="' . _pathologic_url_to_protocol_relative(_pathologic_content_url('foo.jpeg', array('absolute' => TRUE))) . '" />', t('Use global settings when so configured on the format'));
 }
Example #8
0
/**
 * Preprocessor for html.tpl.php
 * Adds meta tag to control viewport, and path to theme in JS.
 */
function plain_response_preprocess_html(&$vars)
{
    $meta = array('#tag' => 'meta', '#attributes' => array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1, minimum-scale=1'));
    drupal_add_html_head($meta, 'plain-response-viewport');
    $settings = array('base_url' => url('<front>', array('absolute' => 'true')), 'theme_path' => path_to_theme(), 'default_scheme' => file_default_scheme());
    foreach (file_get_stream_wrappers() as $name => $wrapper) {
        $settings[$name . '_files'] = file_create_url($name . '://');
    }
    $path = drupal_get_path('theme', 'plain_response');
    drupal_add_js(array('plain_response' => $settings), array('type' => 'setting'));
}
Example #9
0
File: Imce.php Project: aakb/cfia
 /**
  * Returns processed profile configuration for a user.
  */
 public static function userConf(AccountProxyInterface $user = NULL, $scheme = NULL)
 {
     $user = $user ?: \Drupal::currentUser();
     $scheme = isset($scheme) ? $scheme : file_default_scheme();
     if ($profile = static::userProfile($user, $scheme)) {
         $conf = $profile->getConf();
         $conf['pid'] = $profile->id();
         $conf['scheme'] = $scheme;
         return static::processUserConf($conf, $user);
     }
 }
 /**
  * Sets up for multiple values test case.
  */
 protected function setUp()
 {
     parent::setUp();
     // Create test files.
     $this->permanent_file_entity = $this->createPermanentFileEntity();
     $this->temporary_file_entity_1 = $this->createTemporaryFileEntity();
     $this->temporary_file_entity_2 = $this->createTemporaryFileEntity();
     $path = file_default_scheme() . '://' . FILEFIELD_SOURCE_ATTACH_DEFAULT_PATH;
     $this->temporary_file = $this->createTemporaryFile($path);
     // Change allowed number of values.
     $this->drupalPostForm('admin/structure/types/manage/' . $this->typeName . '/fields/node.' . $this->typeName . '.' . $this->fieldName . '/storage', array('cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), t('Save field settings'));
     $this->enableSources(array('upload' => TRUE, 'remote' => TRUE, 'clipboard' => TRUE, 'reference' => TRUE, 'attach' => TRUE));
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     // Enable user pictures.
     \Drupal::state()->set('user_pictures', 1);
     \Drupal::state()->set('user_picture_file_size', '');
     // Set up the pictures directory.
     $picture_path = file_default_scheme() . '://' . \Drupal::state()->get('user_picture_path', 'pictures');
     if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) {
         $this->fail('Could not create directory ' . $picture_path . '.');
     }
     $this->account = $this->drupalCreateUser(array('administer users'));
     $this->drupalLogin($this->account);
 }
Example #12
0
 /**
  * Test the file_save_data() function when no filename is provided.
  */
 function testWithoutFilename()
 {
     $contents = $this->randomName(8);
     $result = file_save_data($contents);
     $this->assertTrue($result, 'Unnamed file saved correctly.');
     $this->assertEqual(file_default_scheme(), file_uri_scheme($result->getFileUri()), "File was placed in Drupal's files directory.");
     $this->assertEqual($result->getFilename(), drupal_basename($result->getFileUri()), "Filename was set to the file's basename.");
     $this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of the file are correct.');
     $this->assertEqual($result->getMimeType(), 'application/octet-stream', 'A MIME type was set.');
     $this->assertTrue($result->isPermanent(), "The file's status was set to permanent.");
     // Check that the correct hooks were called.
     $this->assertFileHooksCalled(array('insert'));
     // Verify that what was returned is what's in the database.
     $this->assertFileUnchanged($result, file_load($result->id(), TRUE));
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $js_injector = $this->entity;
     $status = $js_injector->save();
     switch ($status) {
         case SAVED_NEW:
             drupal_set_message($this->t('Created the %label Js Injector.', ['%label' => $js_injector->label()]));
             break;
         default:
             drupal_set_message($this->t('Saved the %label Js Injector.', ['%label' => $js_injector->label()]));
             $file_name = file_default_scheme() . '://js_injector/' . $js_injector->id . '.js';
             file_unmanaged_delete_recursive($file_name);
     }
     drupal_flush_all_caches();
     $form_state->setRedirectUrl($js_injector->urlInfo('collection'));
 }
 /**
  * Test the file_unmanaged_save_data() function.
  */
 function testFileSaveData()
 {
     $contents = $this->randomMachineName(8);
     $this->settingsSet('file_chmod_file', 0777);
     // No filename.
     $filepath = file_unmanaged_save_data($contents);
     $this->assertTrue($filepath, 'Unnamed file saved correctly.');
     $this->assertEqual(file_uri_scheme($filepath), file_default_scheme(), "File was placed in Drupal's files directory.");
     $this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
     // Provide a filename.
     $filepath = file_unmanaged_save_data($contents, 'public://asdf.txt', FILE_EXISTS_REPLACE);
     $this->assertTrue($filepath, 'Unnamed file saved correctly.');
     $this->assertEqual('asdf.txt', drupal_basename($filepath), 'File was named correctly.');
     $this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
     $this->assertFilePermissions($filepath, 0777);
 }
  /**
   * Overrides \RestfulEntityBase::__construct()
   *
   * Set the "options" key from the plugin info, specific for file upload, with
   * the following keys:
   * - "validators": By default no validation is done on the file extensions or
   *   file size.
   * - "scheme": By default the default scheme (e.g. public, private) is used.
   */
  public function __construct(array $plugin, \RestfulAuthenticationManager $auth_manager = NULL, \DrupalCacheInterface $cache_controller = NULL, $language = NULL) {
    parent::__construct($plugin, $auth_manager, $cache_controller, $language);

    if (!$options = $this->getPluginKey('options')) {
      $options = array();
    }

    $default_values = array(
      'validators' => array(
        'file_validate_extensions' => array(),
        'file_validate_size' => array(),
      ),
      'scheme' => file_default_scheme(),
      'replace' => FILE_EXISTS_RENAME,
    );

    $this->setPluginKey('options', drupal_array_merge_deep($default_values, $options));
  }
 public function testUserTokens()
 {
     // Enable user pictures.
     \Drupal::state()->set('user_pictures', 1);
     \Drupal::state()->set('user_picture_file_size', '');
     // Set up the pictures directory.
     $picture_path = file_default_scheme() . '://' . \Drupal::state()->get('user_picture_path', 'pictures');
     if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) {
         $this->fail('Could not create directory ' . $picture_path . '.');
     }
     // Add a user picture to the account.
     $image = current($this->drupalGetTestFiles('image'));
     $edit = array('files[user_picture_0]' => drupal_realpath($image->uri));
     $this->drupalPostForm('user/' . $this->account->id() . '/edit', $edit, t('Save'));
     $storage = \Drupal::entityTypeManager()->getStorage('user');
     // Load actual user data from database.
     $storage->resetCache();
     $this->account = $storage->load($this->account->id());
     $this->assertTrue(!empty($this->account->user_picture->target_id), 'User picture uploaded.');
     $picture = ['#theme' => 'user_picture', '#account' => $this->account];
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $user_tokens = array('picture' => $renderer->renderPlain($picture), 'picture:fid' => $this->account->user_picture->target_id, 'picture:size-raw' => 125, 'ip-address' => NULL, 'roles' => implode(', ', $this->account->getRoles()));
     $this->assertTokens('user', array('user' => $this->account), $user_tokens);
     // Remove the simpletest-created user role.
     $roles = $this->account->getRoles();
     $this->account->removeRole(end($roles));
     $this->account->save();
     // Remove the user picture field and reload the user.
     FieldStorageConfig::loadByName('user', 'user_picture')->delete();
     $storage->resetCache();
     $this->account = $storage->load($this->account->id());
     $user_tokens = array('picture' => NULL, 'picture:fid' => NULL, 'ip-address' => NULL, 'roles' => 'authenticated', 'roles:keys' => (string) DRUPAL_AUTHENTICATED_RID);
     $this->assertTokens('user', array('user' => $this->account), $user_tokens);
     // The ip address token should work for the current user token type.
     $tokens = array('ip-address' => \Drupal::request()->getClientIp());
     $this->assertTokens('current-user', array(), $tokens);
     $anonymous = new AnonymousUserSession();
     $tokens = array('roles' => 'anonymous', 'roles:keys' => (string) DRUPAL_ANONYMOUS_RID);
     $this->assertTokens('user', array('user' => $anonymous), $tokens);
 }
Example #17
0
/**
 * Implements theme_settings().
 */
function nuboot_radix_form_system_theme_settings_alter(&$form, &$form_state)
{
    // Ensure this include file is loaded when the form is rebuilt from the cache.
    $form_state['build_info']['files']['form'] = drupal_get_path('theme', 'nuboot_radix') . '/theme-settings.php';
    // Add theme settings here.
    $form['nuboot_radix_theme_settings'] = array('#title' => t('Theme Settings'), '#type' => 'fieldset');
    // Copyright.
    $copyright = theme_get_setting('copyright');
    $form['nuboot_radix_theme_settings']['copyright'] = array('#title' => t('Copyright'), '#type' => 'text_format', '#format' => 'html', '#default_value' => isset($copyright['value']) ? $copyright['value'] : t('Powered by Drupal, not for clinical or production use!!'));
    // Hero fieldset.
    $form['hero'] = array('#type' => 'fieldset', '#title' => t('Hero Unit'), '#group' => 'general');
    // Upload field.
    $form['hero']['hero_file'] = array('#type' => 'managed_file', '#title' => t('Upload a new photo for the hero section background'), '#description' => t('<p>The hero unit is the large featured area located on the front page. 
      This theme supplies a default background image for this area. You may upload a different 
      photo here and it will replace the default background image.</p><p>Max. file size: 2 MB
      <br>Recommended pixel size: 1920 x 400<br>Allowed extensions: .png .jpg .jpeg</p>'), '#required' => FALSE, '#upload_location' => file_default_scheme() . '://theme/backgrounds/', '#default_value' => theme_get_setting('hero_file'), '#upload_validators' => array('file_validate_extensions' => array('gif png jpg jpeg')));
    // Solid color background.
    $form['hero']['background_option'] = array('#type' => 'textfield', '#title' => t('Solid color option'), '#description' => t('<p>Enter a hex value here to use a solid background color rather than an image in the hero unit. Make sure the image field above is empty.'), '#required' => FALSE, '#default_value' => theme_get_setting('background_option'), '#element_validate' => array('_background_option_setting'));
    // Return the additional form widgets.
    return $form;
}
Example #18
0
/**
 * Implements theme_settings().
 */
function nuboot_radix_form_system_theme_settings_alter(&$form, &$form_state)
{
    //drupal_set_message('<pre>' . print_r($form, TRUE) . '</pre>');
    // Ensure this include file is loaded when the form is rebuilt from the cache.
    $form_state['build_info']['files']['form'] = drupal_get_path('theme', 'nuboot_radix') . '/theme-settings.php';
    // Add theme settings here.
    $form['nuboot_radix_theme_settings'] = array('#title' => t('Theme Settings'), '#type' => 'fieldset');
    // Copyright.
    $copyright = theme_get_setting('copyright');
    $form['nuboot_radix_theme_settings']['copyright'] = array('#title' => t('Copyright'), '#type' => 'text_format', '#format' => 'html', '#default_value' => isset($copyright['value']) ? $copyright['value'] : t('Powered by <a href="http://nucivic.com/dkan">DKAN</a>, a project of <a href="http://nucivic.com">NuCivic</a>'));
    // Hero fieldset.
    $form['hero'] = array('#type' => 'fieldset', '#title' => t('Hero Unit'), '#group' => 'general');
    // Upload field.
    $form['hero']['hero_file'] = array('#type' => 'managed_file', '#title' => t('Upload a new photo for the hero section background'), '#description' => t('<p>The hero unit is the large featured area located on the front page. 
      This theme supplies a default background image for this area. You may upload a different 
      photo here and it will replace the default background image.</p><p>Max. file size: 2 MB
      <br>Recommended pixel size: 1920 x 400<br>Allowed extensions: .png .jpg .jpeg</p>'), '#required' => FALSE, '#upload_location' => file_default_scheme() . '://theme/backgrounds/', '#default_value' => theme_get_setting('hero_file'), '#upload_validators' => array('file_validate_extensions' => array('gif png jpg jpeg')));
    // Solid color background.
    $form['hero']['background_option'] = array('#type' => 'textfield', '#title' => t('Solid color option'), '#description' => t('<p>Enter a hex value here to use a solid background color rather than an image in the hero unit. Make sure the image field above is empty.'), '#required' => FALSE, '#default_value' => theme_get_setting('background_option'), '#element_validate' => array('_background_option_setting'));
    // Add svg logo option.
    $form['logo']['settings']['svg_logo'] = array('#type' => 'managed_file', '#title' => t('Upload an .svg version of your logo'), '#description' => t('<p>Be sure to also add a .png version of your logo with the <em>Upload logo image</em> field above for older browsers that do not support .svg files. Both files should have the same name, only the suffix should change (i.e. logo.png & logo.svg).</p>'), '#required' => FALSE, '#upload_location' => file_default_scheme() . '://', '#default_value' => theme_get_setting('svg_logo'), '#upload_validators' => array('file_validate_extensions' => array('svg')));
    // Return the additional form widgets.
    return $form;
}
Example #19
0
 /**
  * Implements hook_filefield_source_settings().
  */
 public static function settings(WidgetInterface $plugin)
 {
     $settings = $plugin->getThirdPartySetting('filefield_sources', 'filefield_sources', array('source_attach' => array('path' => FILEFIELD_SOURCE_ATTACH_DEFAULT_PATH, 'absolute' => FILEFIELD_SOURCE_ATTACH_RELATIVE, 'attach_mode' => FILEFIELD_SOURCE_ATTACH_MODE_MOVE)));
     $return['source_attach'] = array('#title' => t('File attach settings'), '#type' => 'details', '#description' => t('File attach allows for selecting a file from a directory on the server, commonly used in combination with FTP.') . ' <strong>' . t('This file source will ignore file size checking when used.') . '</strong>', '#element_validate' => array(array(get_called_class(), 'filePathValidate')), '#weight' => 3);
     $return['source_attach']['path'] = array('#type' => 'textfield', '#title' => t('File attach path'), '#default_value' => $settings['source_attach']['path'], '#size' => 60, '#maxlength' => 128, '#description' => t('The directory within the <em>File attach location</em> that will contain attachable files.'));
     if (\Drupal::moduleHandler()->moduleExists('token')) {
         $return['source_attach']['tokens'] = array('#theme' => 'token_tree', '#token_types' => array('user'));
     }
     $return['source_attach']['absolute'] = array('#type' => 'radios', '#title' => t('File attach location'), '#options' => array(FILEFIELD_SOURCE_ATTACH_RELATIVE => t('Within the files directory'), FILEFIELD_SOURCE_ATTACH_ABSOLUTE => t('Absolute server path')), '#default_value' => $settings['source_attach']['absolute'], '#description' => t('The <em>File attach path</em> may be with the files directory (%file_directory) or from the root of your server. If an absolute path is used and it does not start with a "/" your path will be relative to your site directory: %realpath.', array('%file_directory' => drupal_realpath(file_default_scheme() . '://'), '%realpath' => realpath('./'))));
     $return['source_attach']['attach_mode'] = array('#type' => 'radios', '#title' => t('Attach method'), '#options' => array(FILEFIELD_SOURCE_ATTACH_MODE_MOVE => t('Move the file directly to the final location'), FILEFIELD_SOURCE_ATTACH_MODE_COPY => t('Leave a copy of the file in the attach directory')), '#default_value' => isset($settings['source_attach']['attach_mode']) ? $settings['source_attach']['attach_mode'] : 'move');
     return $return;
 }
Example #20
0
 function testFolderSetup()
 {
     $directory = file_default_scheme() . '://styles';
     $this->assertTrue(file_prepare_directory($directory, FALSE), 'Directory created.');
 }
 /**
  * {@inheritdoc}
  */
 public static function defaultStorageSettings()
 {
     return array('target_type' => 'file', 'display_field' => FALSE, 'display_default' => FALSE, 'uri_scheme' => file_default_scheme()) + parent::defaultStorageSettings();
 }
Example #22
0
/**
 * Remove any information that the module sets.
 *
 * The information that the module should remove includes:
 * - state that the module has set using \Drupal::state()
 * - modifications to existing tables
 *
 * The module should not remove its entry from the module configuration.
 * Database tables defined by hook_schema() will be removed automatically.
 *
 * The uninstall hook must be implemented in the module's .install file. It
 * will fire when the module gets uninstalled but before the module's database
 * tables are removed, allowing your module to query its own tables during
 * this routine.
 *
 * @see hook_install()
 * @see hook_schema()
 * @see hook_modules_uninstalled()
 */
function hook_uninstall()
{
    // Remove the styles directory and generated images.
    file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
}
Example #23
0
/**
 * @file
 * Theme settings for the sasson
 */
function sasson_form_system_theme_settings_alter(&$form, &$form_state)
{
    global $theme_key;
    drupal_add_css(drupal_get_path('theme', 'sasson') . '/stylesheets/theme-settings.css');
    drupal_add_js(drupal_get_path('theme', 'sasson') . '/scripts/themeSettings.js');
    $select_toggle = '<br>' . l(t('select all'), '#', array('attributes' => array('class' => 'select-all'))) . ' | ' . l(t('select none'), '#', array('attributes' => array('class' => 'select-none')));
    $form['sasson_settings'] = array('#type' => 'vertical_tabs', '#weight' => -10, '#prefix' => '<h3>' . t('Theme configuration') . '</h3>');
    /**
     * Responsive Layout Settings
     */
    $form['sasson_settings']['sasson_layout'] = array('#type' => 'fieldset', '#title' => t('Responsive Layout Settings'));
    $form['sasson_settings']['sasson_layout']['sasson_responsive'] = array('#type' => 'checkbox', '#title' => t('Enable responsive layout'), '#attributes' => array('class' => array('enable-extension')), '#description' => t("Disable if you don't want your site layout to adapt to small devices, this enables both the css3 media-queries that takes care of adapting the layout and the 'viewport' meta tag that makes sure mobile devices properly display your layout."), '#default_value' => theme_get_setting('sasson_responsive'));
    $form['sasson_settings']['sasson_layout']['sasson_responsive_approach'] = array('#type' => 'radios', '#title' => t('Desktop or Mobile first'), '#options' => array('desktop_first' => t('Desktop first'), 'mobile_first' => t('Mobile first')), '#description' => t('Select they way your responsive layout should be constructed. desktop-first means we start with desktop size page and reduce accordingly, mobile-first means we start with a very simple layout and build on top of that.'), '#default_value' => theme_get_setting('sasson_responsive_approach'));
    $form['sasson_settings']['sasson_layout']['media_break_points'] = array('#markup' => '<strong>' . t('Media queries break-point are being set via <code>!settings</code>. Copy it to your sub-theme and set your own values.', array('!settings' => l('_settings.scss', 'http://drupalcode.org/project/sasson.git/blob/refs/heads/7.x-3.x:/sass/_settings.scss', array('attributes' => array('target' => '_blank'))))) . '</strong>');
    $form['sasson_settings']['sasson_layout']['responsive_menus'] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Responsive menus'));
    $form['sasson_settings']['sasson_layout']['responsive_menus']['sasson_responsive_menus_width'] = array('#type' => 'textfield', '#size' => 10, '#title' => t('Responsive menus page width'), '#description' => t("Set the width in which the selected menus turn into a select menu, or 0 to disable."), '#default_value' => theme_get_setting('sasson_responsive_menus_width'));
    $form['sasson_settings']['sasson_layout']['responsive_menus']['sasson_responsive_menus_selectors'] = array('#type' => 'textfield', '#title' => t('Responsive menus selectors'), '#description' => t("Enter some CSS selectors for the menus you want to alter."), '#default_value' => theme_get_setting('sasson_responsive_menus_selectors'));
    $form['sasson_settings']['sasson_layout']['responsive_menus']['sasson_responsive_menus_autohide'] = array('#type' => 'checkbox', '#title' => t('Auto-hide the standard menu'), '#default_value' => theme_get_setting('sasson_responsive_menus_autohide'));
    /**
     * CSS settings
     */
    $form['sasson_settings']['sasson_css'] = array('#type' => 'fieldset', '#title' => t('CSS settings'));
    $form['sasson_settings']['sasson_css']['sasson_reset'] = array('#type' => 'fieldset', '#title' => t('CSS Reset VS Normalize'));
    $form['sasson_settings']['sasson_css']['sasson_reset']['sasson_cssreset'] = array('#type' => 'radios', '#options' => array('normalize' => t('Use !normalize from !h5bp.', array('!normalize' => l('normalize.css', 'http://necolas.github.com/normalize.css/', array('attributes' => array('target' => '_blank'))), '!h5bp' => l('HTML5 Boilerplate', 'http://html5boilerplate.com/', array('attributes' => array('target' => '_blank'))))), 'reset' => t("Use !meyer's CSS reset.", array('!meyer' => l('Eric Meyer', 'http://meyerweb.com/eric/tools/css/reset/', array('attributes' => array('target' => '_blank'))))), 'none' => t("None")), '#description' => t('Normalize.css makes browsers render all elements more consistently and in line with modern standards, while preserving useful defaults.<br>
      Reset.css will reset css values (e.g. set 0) to reduce browser inconsistencies in things like default line heights, margins and font sizes.'), '#default_value' => theme_get_setting('sasson_cssreset'));
    $form['sasson_settings']['sasson_css']['sasson_forms'] = array('#type' => 'fieldset', '#title' => t('Forms styling'));
    $form['sasson_settings']['sasson_css']['sasson_forms']['sasson_formalize'] = array('#type' => 'checkbox', '#title' => t("Use !formalize to reset your forms.", array('!formalize' => l('Formalize', 'http://formalize.me/', array('attributes' => array('target' => '_blank'))))), '#description' => t('Apply consistent and cross-browser styles to all forms.'), '#default_value' => theme_get_setting('sasson_formalize'));
    // Disable CSS
    require_once drupal_get_path('theme', 'sasson') . '/includes/assets.inc';
    $form['sasson_settings']['sasson_css']['sasson_disablecss'] = array('#type' => 'fieldset', '#title' => t('Disable CSS files'));
    $form['sasson_settings']['sasson_css']['sasson_disablecss']['sasson_disable_css'] = array('#type' => 'checkbox', '#title' => t("Enable this extension."), '#attributes' => array('class' => array('enable-extension')), '#description' => t('Disable all CSS files included by core and contrib modules or choose specific CSS files to disable.'), '#default_value' => theme_get_setting('sasson_disable_css'));
    $form['sasson_settings']['sasson_css']['sasson_disablecss']['modules'] = array('#type' => 'fieldset', '#title' => t('Per module'), '#description' => t('Disable all CSS files from selected modules.') . $select_toggle, '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['sasson_settings']['sasson_css']['sasson_disablecss']['modules']['sasson_disable_css_modules'] = array('#type' => 'checkboxes', '#title' => t('Modules'), '#options' => sasson_get_modules_list(), '#default_value' => theme_get_setting('sasson_disable_css_modules') ? theme_get_setting('sasson_disable_css_modules') : array());
    $form['sasson_settings']['sasson_css']['sasson_disablecss']['files'] = array('#type' => 'fieldset', '#title' => t('Specific CSS files'), '#description' => t('Disable specific CSS files from core and contrib modules.') . $select_toggle, '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['sasson_settings']['sasson_css']['sasson_disablecss']['files']['sasson_disable_css_files'] = array('#type' => 'checkboxes', '#title' => t('Disable specific css files.'), '#options' => sasson_get_assets_list(), '#default_value' => theme_get_setting('sasson_disable_css_files') ? theme_get_setting('sasson_disable_css_files') : array());
    /**
     * JavaScript Settings
     */
    $form['sasson_settings']['sasson_js'] = array('#type' => 'fieldset', '#title' => t('JavaScript Settings'));
    $form['sasson_settings']['sasson_js']['sasson_js_footer_wrapper'] = array('#type' => 'fieldset', '#title' => t('Move JavaScript to footer'));
    $form['sasson_settings']['sasson_js']['sasson_js_footer_wrapper']['sasson_js_footer'] = array('#type' => 'checkbox', '#title' => t('Move all scripts to the footer.'), '#description' => t('Yahoo! Exceptional Performance team recommends <a href="http://developer.yahoo.com/performance/rules.html#js_bottom">placing scripts at the bottom of your page</a> because of the way browsers download components.') . '<br>' . t('This will move all your scripts to the bottom of your page. You can still force a script to go in the <code>head</code> by setting <code>"force_header" => TRUE</code> in your !drupal_add_js options array.', array('!drupal_add_js' => l('drupal_add_js', 'http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_js', array('attributes' => array('target' => '_blank'))))), '#default_value' => theme_get_setting('sasson_js_footer'));
    $form['sasson_settings']['sasson_js']['sasson_latestjs'] = array('#type' => 'fieldset', '#title' => t('Latest jQuery from Google'));
    $form['sasson_settings']['sasson_js']['sasson_latestjs']['sasson_latest_jquery'] = array('#type' => 'checkbox', '#title' => t('Replace core\'s jQuery with latest version from Google\'s CDN.'), '#default_value' => theme_get_setting('sasson_latest_jquery'), '#description' => t('<strong>Note:</strong> this might break scripts that depend on deprecated jQuery features.'));
    // Disable JS
    $form['sasson_settings']['sasson_js']['sasson_disablejs'] = array('#type' => 'fieldset', '#title' => t('Disable JS files'));
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['sasson_disable_js'] = array('#type' => 'checkbox', '#title' => t("Enable this extension."), '#attributes' => array('class' => array('enable-extension')), '#description' => t('Disable all JS files included by core and contrib modules or choose specific JS files to disable.'), '#default_value' => theme_get_setting('sasson_disable_js'));
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['modules'] = array('#type' => 'fieldset', '#title' => t('Per module'), '#description' => t('Disable all JS files from selected modules.') . $select_toggle, '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['modules']['sasson_disable_js_modules'] = array('#type' => 'checkboxes', '#title' => t('Modules'), '#options' => sasson_get_modules_list(), '#default_value' => theme_get_setting('sasson_disable_js_modules') ? theme_get_setting('sasson_disable_js_modules') : array());
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['files'] = array('#type' => 'fieldset', '#title' => t('Specific JS files'), '#description' => t('Disable specific JS files from core and contrib modules.') . $select_toggle, '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['files']['sasson_disable_js_files'] = array('#type' => 'checkboxes', '#title' => t('Disable specific JS files.'), '#options' => sasson_get_assets_list('js'), '#default_value' => theme_get_setting('sasson_disable_js_files') ? theme_get_setting('sasson_disable_js_files') : array());
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['jquery'] = array('#type' => 'fieldset', '#title' => t('Core jQuery & jQuery UI'), '#description' => t('Disable specific jQuery & jQuery UI files from core.') . $select_toggle, '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['jquery']['sasson_disable_jquery_files'] = array('#type' => 'checkboxes', '#title' => t('Disable core jQuery & jQuery UI files.'), '#options' => sasson_get_assets_list('js', 'jquery'), '#default_value' => theme_get_setting('sasson_disable_jquery_files') ? theme_get_setting('sasson_disable_jquery_files') : array());
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['sasson_js'] = array('#type' => 'fieldset', '#title' => t('Sasson\'s JS'));
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['sasson_js']['sasson_disable_sasson_js'] = array('#type' => 'checkbox', '#title' => t('Disable all JS from Sasson.'), '#description' => t('<strong>Note:</strong> this will break Sasson\'s scripts like the file-watcher and mobile menus if they are enabled, be warned.'), '#default_value' => theme_get_setting('sasson_disable_sasson_js'));
    /**
     * HTML5 IE support
     */
    $form['sasson_settings']['sasson_html5'] = array('#type' => 'fieldset', '#title' => t('HTML5 IE support'));
    $form['sasson_settings']['sasson_html5']['sasson_force_ie'] = array('#type' => 'checkbox', '#title' => t('Force latest IE rendering engine (even in intranet) & Chrome Frame'), '#default_value' => theme_get_setting('sasson_force_ie'));
    $form['sasson_settings']['sasson_html5']['sasson_html5shiv'] = array('#type' => 'checkbox', '#title' => t('Enable HTML5 elements in IE'), '#description' => t('Makes IE understand HTML5 elements via <a href="!shivlink">HTML5 shiv</a>. disable if you use a different method.', array('!shivlink' => 'http://code.google.com/p/html5shiv/')), '#default_value' => theme_get_setting('sasson_html5shiv'));
    $form['sasson_settings']['sasson_html5']['sasson_ie_comments'] = array('#type' => 'checkbox', '#title' => t('Add IE specific classes'), '#description' => t('This will add conditional classes to the html tag for IE specific styling. see this <a href="!post">post</a> for more info.', array('!post' => 'http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/')), '#default_value' => theme_get_setting('sasson_ie_comments'));
    $form['sasson_settings']['sasson_html5']['sasson_prompt_cf'] = array('#type' => 'select', '#title' => t('Prompt old IE users to update'), '#default_value' => theme_get_setting('sasson_prompt_cf'), '#options' => drupal_map_assoc(array('Disabled', 'IE 6', 'IE 7', 'IE 8', 'IE 9')), '#description' => t('Set the latest IE version you would like the prompt box to show on or disable if you want to support old IEs.'));
    /**
     * Fonts
     */
    $form['sasson_settings']['sasson_fonts'] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t("\n      Set a custom font to be used across the site. you may override typography settings in you sub-theme's css/sass/scss files.<br>\n      <strong>Note:</strong> Only fonts from !webfont are supported at the moment, if this is not enough you should check out !fontyourface module.", array('!webfont' => l('google web fonts', 'http://www.google.com/webfonts', array('attributes' => array('target' => '_blank'))), '!fontyourface' => l('@font-your-face', 'http://drupal.org/project/fontyourface', array('attributes' => array('target' => '_blank'))))), '#title' => t('Fonts'));
    $form['sasson_settings']['sasson_fonts']['sasson_font'] = array('#type' => 'textfield', '#title' => t('Font name'), '#description' => t("Enter the font name from Google web fonts."), '#default_value' => theme_get_setting('sasson_font'));
    $form['sasson_settings']['sasson_fonts']['sasson_font_fallback'] = array('#type' => 'textfield', '#title' => t('Font fallback'), '#description' => t("Enter the font names you would like as a fallback in a comma separated list. e.g. <code>'Times New Roman', Times, serif</code>."), '#default_value' => theme_get_setting('sasson_font_fallback'));
    $form['sasson_settings']['sasson_fonts']['sasson_font_selectors'] = array('#type' => 'textfield', '#title' => t('CSS selectors'), '#description' => t("Enter some CSS selectors for the fonts to apply to. if none is provided it will default to a <code>.sasson-font-face</code> class"), '#default_value' => theme_get_setting('sasson_font_selectors'));
    /**
     * Development Settings
     */
    $form['sasson_settings']['sasson_development'] = array('#type' => 'fieldset', '#title' => t('Development'));
    $form['sasson_settings']['sasson_development']['sasson_watch'] = array('#type' => 'fieldset', '#title' => t('File Watcher'));
    $form['sasson_settings']['sasson_development']['sasson_watch']['sasson_watcher'] = array('#type' => 'checkbox', '#title' => t('Watch for file changes and automatically refresh the browser.'), '#attributes' => array('class' => array('enable-extension')), '#description' => t('With this feature on, you may enter a list of URLs for files to be watched, whenever a file is changed, your browser will automagically update itself.<br><strong>Turn this off when not actively developing.</strong>'), '#default_value' => theme_get_setting('sasson_watcher'));
    $form['sasson_settings']['sasson_development']['sasson_watch']['sasson_watch_file'] = array('#type' => 'textarea', '#title' => t('Files to watch'), '#description' => t('Enter the internal path of the files to be watched. one file per line. no leading slash.<br> e.g. sites/all/themes/sasson/stylesheets/sasson.scss<br>Lines starting with a semicolon (;) will be ignored.<br><strong>Keep this list short !</strong> Watch only the files you currently work on.'), '#rows' => 3, '#default_value' => theme_get_setting('sasson_watch_file'));
    $form['sasson_settings']['sasson_development']['sasson_grid'] = array('#type' => 'fieldset', '#title' => t('Grid background'));
    $form['sasson_settings']['sasson_development']['sasson_grid']['sasson_show_grid'] = array('#type' => 'checkbox', '#title' => t('Show grid background layer.'), '#description' => t('Display a visible background grid, for easier elements positioning'), '#default_value' => theme_get_setting('sasson_show_grid'));
    $form['sasson_settings']['sasson_development']['sasson_overlay'] = array('#type' => 'fieldset', '#title' => t('Design Overlay'));
    $form['sasson_settings']['sasson_development']['sasson_overlay']['sasson_overlay'] = array('#type' => 'checkbox', '#title' => t('Enable overlay image'), '#attributes' => array('class' => array('enable-extension')), '#description' => t('With this feature on, you may upload an image that will be place as a draggable overlay image over your HTML for easy visual comparison. you may also set different overlay opacity.'), '#default_value' => theme_get_setting('sasson_overlay'));
    $form['sasson_settings']['sasson_development']['sasson_overlay']['sasson_overlay_file'] = array('#type' => 'managed_file', '#title' => t('Upload overlay image'), '#upload_location' => file_default_scheme() . '://sasson/overlay/', '#default_value' => theme_get_setting('sasson_overlay_file'), '#upload_validators' => array('file_validate_extensions' => array('gif png jpg jpeg')));
    $form['sasson_settings']['sasson_development']['sasson_overlay']['sasson_overlay_opacity'] = array('#type' => 'select', '#title' => t('Overlay opacity'), '#default_value' => theme_get_setting('sasson_overlay_opacity'), '#options' => drupal_map_assoc(array('0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1')));
    $form['sasson_settings']['sasson_development']['sasson_mail_dev'] = array('#type' => 'fieldset', '#title' => t('HTML Mail debugger'), '#description' => t('Useful tools for HTML mail development.') . $select_toggle);
    $debug_file = DRUPAL_ROOT . '/' . file_directory_temp() . '/mail_debug/mail_debug.html';
    $form['sasson_settings']['sasson_development']['sasson_mail_dev']['sasson_mail_to_file'] = array('#type' => 'checkbox', '#title' => t('Write mail messages to file'), '#description' => t('All mail messages will be written to <code>!file</code>', array('!file' => $debug_file)), '#default_value' => theme_get_setting('sasson_mail_to_file'));
    $form['sasson_settings']['sasson_development']['sasson_mail_dev']['sasson_mail_to_log'] = array('#type' => 'checkbox', '#title' => t('Write mail messages to log'), '#description' => t('All mail messages will be logged to the !db.', array('!db' => l('database', 'admin/reports/dblog'))), '#default_value' => theme_get_setting('sasson_mail_to_log'));
    $form['sasson_settings']['sasson_development']['sasson_mail_dev']['sasson_mail_devel'] = array('#type' => 'checkbox', '#title' => t('Display development messages'), '#description' => t('Show a development message after mail is sent (requires devel module)'), '#default_value' => theme_get_setting('sasson_mail_devel'));
    $form['sasson_settings']['sasson_development']['sasson_mail_dev']['sasson_mail_prevent'] = array('#type' => 'checkbox', '#title' => t('Prevent mail from being sent'), '#description' => t('Prevent outgoing mail messages from being sent while developing.'), '#default_value' => theme_get_setting('sasson_mail_prevent'));
    /**
     * General Settings
     */
    $form['sasson_settings']['sasson_general'] = array('#type' => 'fieldset', '#title' => t('General'));
    $admin_theme = variable_get('admin_theme', 0);
    if (!empty($admin_theme) && $admin_theme != $theme_key) {
        $form['sasson_settings']['sasson_general']['theme_settings'] = $form['theme_settings'];
        $form['sasson_settings']['sasson_general']['logo'] = $form['logo'];
        $form['sasson_settings']['sasson_general']['favicon'] = $form['favicon'];
        unset($form['theme_settings']);
        unset($form['logo']);
        unset($form['favicon']);
    } else {
        $form['theme_settings']['#collapsible'] = TRUE;
        $form['theme_settings']['#collapsed'] = TRUE;
        $form['logo']['#collapsible'] = TRUE;
        $form['logo']['#collapsed'] = TRUE;
        $form['favicon']['#collapsible'] = TRUE;
        $form['favicon']['#collapsed'] = TRUE;
    }
    $form['sasson_settings']['sasson_general']['sasson_breadcrumb'] = array('#type' => 'fieldset', '#title' => t('Breadcrumbs'));
    $form['sasson_settings']['sasson_general']['sasson_breadcrumb']['sasson_breadcrumb_hideonlyfront'] = array('#type' => 'checkbox', '#title' => t('Hide the breadcrumb if the breadcrumb only contains the link to the front page.'), '#default_value' => theme_get_setting('sasson_breadcrumb_hideonlyfront'));
    $form['sasson_settings']['sasson_general']['sasson_breadcrumb']['sasson_breadcrumb_showtitle'] = array('#type' => 'checkbox', '#title' => t('Show page title on breadcrumb.'), '#default_value' => theme_get_setting('sasson_breadcrumb_showtitle'));
    $form['sasson_settings']['sasson_general']['sasson_breadcrumb']['sasson_breadcrumb_separator'] = array('#type' => 'textfield', '#title' => t('Breadcrumb separator'), '#default_value' => theme_get_setting('sasson_breadcrumb_separator'));
    $form['sasson_settings']['sasson_general']['sasson_rss'] = array('#type' => 'fieldset', '#title' => t('RSS'));
    $form['sasson_settings']['sasson_general']['sasson_rss']['sasson_feed_icons'] = array('#type' => 'checkbox', '#title' => t('Display Feed Icons'), '#default_value' => theme_get_setting('sasson_feed_icons'));
}
Example #24
0
 /**
  * Try deleting a missing file.
  */
 function testMissing()
 {
     // Try to delete a non-existing file
     $this->assertTrue(file_unmanaged_delete(file_default_scheme() . '/' . $this->randomName()), 'Returns true when deleting a non-existent file.');
 }
 /**
  * Provides a wrapper for file_default_scheme() to allow unit testing.
  *
  * Gets the default file stream implementation.
  *
  * @todo: Convert file_default_scheme() into a proper injectable service.
  *
  * @return string
  *   'public', 'private' or any other file scheme defined as the default.
  */
 protected function fileDefaultScheme()
 {
     return file_default_scheme();
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function buildUri($uri)
 {
     $scheme = file_uri_scheme($uri);
     if ($scheme) {
         $path = file_uri_target($uri);
     } else {
         $path = $uri;
         $scheme = file_default_scheme();
     }
     return $scheme . '://styles/' . $this->id() . '/' . $scheme . '/' . $path;
 }
Example #27
0
 /**
  * Creates a file and returns its URI.
  *
  * @param string $filepath
  *   Optional string specifying the file path. If none is provided then a
  *   randomly named file will be created in the site's files directory.
  * @param string $contents
  *   Optional contents to save into the file. If a NULL value is provided an
  *   arbitrary string will be used.
  * @param string $scheme
  *   Optional string indicating the stream scheme to use. Drupal core includes
  *   public, private, and temporary. The public wrapper is the default.
  *
  * @return string
  *   File URI.
  */
 function createUri($filepath = NULL, $contents = NULL, $scheme = NULL)
 {
     if (!isset($filepath)) {
         // Prefix with non-latin characters to ensure that all file-related
         // tests work with international filenames.
         $filepath = 'Файл для тестирования ' . $this->randomMachineName();
     }
     if (!isset($scheme)) {
         $scheme = file_default_scheme();
     }
     $filepath = $scheme . '://' . $filepath;
     if (!isset($contents)) {
         $contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data.";
     }
     file_put_contents($filepath, $contents);
     $this->assertTrue(is_file($filepath), t('The test file exists on the disk.'), 'Create test file');
     return $filepath;
 }
Example #28
0
$password = '******';
# set up connection and repository variables
$connection = new RepositoryConnection($url, $username, $password);
$repository = new FedoraRepository(new FedoraApi($connection), new SimpleCache());
$root_pid = drush_shift();
$parent_obj = $repository->getObject($root_pid);
$itql = 'select $page_itql from <#ri>
        where $page_itql <fedora-rels-ext:isMemberOf> <info:fedora/' . $root_pid . '>
        order by $page_itql';
$page_objects = $repository->ri->itqlQuery($itql, 'unlimited', '0');
foreach ($page_objects as $page) {
    $page_pid = $page['page_itql']['value'];
    $object = islandora_object_load($page_pid);
    if (!$object->getDataStream('JP2')) {
        echo "regenerating OBJ for {$page_pid}\n";
        $obj_ds = $object['OBJ'];
        //url of image... http://fedora_repo_url:8080/objects/[pid]/datastreams/OBJ/content
        $file_url = $repo_url . '/objects/' . $page_pid . '/datastreams/OBJ/content';
        $drupal_result = drupal_http_request($file_url);
        if (!empty($drupal_result->data)) {
            //create a temporary file
            $new_file = file_save_data($drupal_result->data, file_default_scheme() . '://');
            $path = drupal_realpath($new_file->uri);
            //replace file...
            $obj_ds->setContentFromFile($path);
            //delete temporary file
            file_delete($new_file);
            echo "regenerating OBJ for {$page_pid} completed\n";
        }
    }
}
 /**
  * General test to add a style, add/remove/edit effects to it, then delete it.
  */
 function testStyle()
 {
     $admin_path = 'admin/config/media/image-styles';
     // 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_path . '/manage/' . $style_name;
     $effect_edits = array('image_resize' => array('width' => 100, 'height' => 101), 'image_scale' => array('width' => 110, 'height' => 111, 'upscale' => 1), 'image_scale_and_crop' => array('width' => 120, 'height' => 121), 'image_crop' => array('width' => 130, 'height' => 131, 'anchor' => 'left-top'), 'image_desaturate' => array(), 'image_rotate' => array('degrees' => 5, 'random' => 1, 'bgcolor' => '#FFFF00'));
     // Add style form.
     $edit = array('name' => $style_name, 'label' => $style_label);
     $this->drupalPostForm($admin_path . '/add', $edit, t('Create new style'));
     $this->assertRaw(t('Style %name was created.', array('%name' => $style_label)));
     // Ensure that the expected entity operations are there.
     $this->drupalGet($admin_path);
     $this->assertLinkByHref($style_path);
     $this->assertLinkByHref($style_path . '/flush');
     $this->assertLinkByHref($style_path . '/delete');
     // Add effect form.
     // Add each sample effect to the style.
     foreach ($effect_edits as $effect => $edit) {
         $edit_data = array();
         foreach ($edit as $field => $value) {
             $edit_data['data[' . $field . ']'] = $value;
         }
         // Add the effect.
         $this->drupalPostForm($style_path, array('new' => $effect), t('Add'));
         if (!empty($edit)) {
             $this->drupalPostForm(NULL, $edit_data, t('Add effect'));
         }
     }
     // Load the saved image style.
     $style = ImageStyle::load($style_name);
     // Ensure that third party settings were added to the config entity.
     // These are added by a hook_image_style_presave() implemented in
     // image_module_test module.
     $this->assertEqual('bar', $style->getThirdPartySetting('image_module_test', 'foo'), 'Third party settings were added to the image style.');
     // Ensure that the image style URI matches our expected path.
     $style_uri_path = $style->url();
     $this->assertTrue(strpos($style_uri_path, $style_path) !== FALSE, 'The image style URI is correct.');
     // Confirm that all effects on the image style have settings that match
     // what was saved.
     $uuids = array();
     foreach ($style->getEffects() as $uuid => $effect) {
         // Store the uuid for later use.
         $uuids[$effect->getPluginId()] = $uuid;
         $effect_configuration = $effect->getConfiguration();
         foreach ($effect_edits[$effect->getPluginId()] as $field => $value) {
             $this->assertEqual($value, $effect_configuration['data'][$field], SafeMarkup::format('The %field field in the %effect effect has the correct value of %value.', array('%field' => $field, '%effect' => $effect->getPluginId(), '%value' => $value)));
         }
     }
     // Assert that every effect was saved.
     foreach (array_keys($effect_edits) as $effect_name) {
         $this->assertTrue(isset($uuids[$effect_name]), format_string('A %effect_name effect was saved with ID %uuid', array('%effect_name' => $effect_name, '%uuid' => $uuids[$effect_name])));
     }
     // Image style overview form (ordering and renaming).
     // Confirm the order of effects is maintained according to the order we
     // added the fields.
     $effect_edits_order = array_keys($effect_edits);
     $order_correct = TRUE;
     $index = 0;
     foreach ($style->getEffects() as $effect) {
         if ($effect_edits_order[$index] != $effect->getPluginId()) {
             $order_correct = FALSE;
         }
         $index++;
     }
     $this->assertTrue($order_correct, 'The order of the effects is correctly set by default.');
     // Test the style overview form.
     // Change the name of the style and adjust the weights of effects.
     $style_name = strtolower($this->randomMachineName(10));
     $style_label = $this->randomMachineName();
     $weight = count($effect_edits);
     $edit = array('name' => $style_name, 'label' => $style_label);
     foreach ($style->getEffects() as $uuid => $effect) {
         $edit['effects[' . $uuid . '][weight]'] = $weight;
         $weight--;
     }
     // Create an image to make sure it gets flushed after saving.
     $image_path = $this->createSampleImage($style);
     $this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
     $this->drupalPostForm($style_path, $edit, t('Update style'));
     // Note that after changing the style name, the style path is changed.
     $style_path = 'admin/config/media/image-styles/manage/' . $style_name;
     // Check that the URL was updated.
     $this->drupalGet($style_path);
     $this->assertTitle(t('Edit style @name | Drupal', array('@name' => $style_label)));
     $this->assertResponse(200, format_string('Image style %original renamed to %new', array('%original' => $style->id(), '%new' => $style_name)));
     // Check that the image was flushed after updating the style.
     // This is especially important when renaming the style. Make sure that
     // the old image directory has been deleted.
     $this->assertEqual($this->getImageCount($style), 0, format_string('Image style %style was flushed after renaming the style and updating the order of effects.', array('%style' => $style->label())));
     // Load the style by the new name with the new weights.
     $style = ImageStyle::load($style_name);
     // Confirm the new style order was saved.
     $effect_edits_order = array_reverse($effect_edits_order);
     $order_correct = TRUE;
     $index = 0;
     foreach ($style->getEffects() as $effect) {
         if ($effect_edits_order[$index] != $effect->getPluginId()) {
             $order_correct = FALSE;
         }
         $index++;
     }
     $this->assertTrue($order_correct, 'The order of the effects is correctly set by default.');
     // Image effect deletion form.
     // Create an image to make sure it gets flushed after deleting an effect.
     $image_path = $this->createSampleImage($style);
     $this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
     // Delete the 'image_crop' effect from the style.
     $this->drupalPostForm($style_path . '/effects/' . $uuids['image_crop'] . '/delete', array(), t('Delete'));
     // Confirm that the form submission was successful.
     $this->assertResponse(200);
     $image_crop_effect = $style->getEffect($uuids['image_crop']);
     $this->assertRaw(t('The image effect %name has been deleted.', array('%name' => $image_crop_effect->label())));
     // Confirm that there is no longer a link to the effect.
     $this->assertNoLinkByHref($style_path . '/effects/' . $uuids['image_crop'] . '/delete');
     // Refresh the image style information and verify that the effect was
     // actually deleted.
     $style = entity_load_unchanged('image_style', $style->id());
     $this->assertFalse($style->getEffects()->has($uuids['image_crop']), format_string('Effect with ID %uuid no longer found on image style %style', array('%uuid' => $uuids['image_crop'], '%style' => $style->label())));
     // Additional test on Rotate effect, for transparent background.
     $edit = array('data[degrees]' => 5, 'data[random]' => 0, 'data[bgcolor]' => '');
     $this->drupalPostForm($style_path, array('new' => 'image_rotate'), t('Add'));
     $this->drupalPostForm(NULL, $edit, t('Add effect'));
     $style = entity_load_unchanged('image_style', $style_name);
     $this->assertEqual(count($style->getEffects()), 6, 'Rotate effect with transparent background was added.');
     // Style deletion form.
     // Delete the style.
     $this->drupalPostForm($style_path . '/delete', array(), t('Delete'));
     // Confirm the style directory has been removed.
     $directory = file_default_scheme() . '://styles/' . $style_name;
     $this->assertFalse(is_dir($directory), format_string('Image style %style directory removed on style deletion.', array('%style' => $style->label())));
     $this->assertFalse(ImageStyle::load($style_name), format_string('Image style %style successfully deleted.', array('%style' => $style->label())));
 }
 /**
  * Test supported element types.
  */
 public function testSupportedElementTypes()
 {
     // Associate the unicorn text editor with the "Full HTML" text format.
     $editor = entity_create('editor', array('format' => 'full_html', 'editor' => 'unicorn', 'image_upload' => array('status' => FALSE, 'scheme' => file_default_scheme(), 'directory' => 'inline-images', 'max_size' => '', 'max_dimensions' => array('width' => '', 'height' => ''))));
     $editor->save();
     // Create an "page" node that uses the full_html text format.
     $this->drupalCreateNode(array('type' => 'page', 'field_text' => array(array('value' => $this->randomMachineName(32), 'format' => 'full_html'))));
     // Assert the unicorn editor works with textfields.
     $this->drupalLogin($this->privilegedUser);
     $this->drupalGet('node/1/edit');
     list(, $editor_settings_present, $editor_js_present, $field, $format_selector) = $this->getThingsToCheck('field-text', 'input');
     $this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page.");
     $this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.');
     $this->assertTrue(count($field) === 1, 'A text field exists.');
     $this->assertTrue(count($format_selector) === 1, 'A single text format selector exists on the page.');
     $specific_format_selector = $this->xpath('//select[contains(@class, "filter-list") and contains(@class, "editor") and @data-editor-for="edit-field-text-0-value"]');
     $this->assertTrue(count($specific_format_selector) === 1, 'A single text format selector exists on the page and has the "editor" class and a "data-editor-for" attribute with the correct value.');
     // Associate the trex text editor with the "Full HTML" text format.
     $editor->delete();
     entity_create('editor', array('format' => 'full_html', 'editor' => 'trex'))->save();
     $this->drupalGet('node/1/edit');
     list(, $editor_settings_present, $editor_js_present, $field, $format_selector) = $this->getThingsToCheck('field-text', 'input');
     $this->assertFalse($editor_settings_present, "Text Editor module's JavaScript settings are not on the page.");
     $this->assertFalse($editor_js_present, 'Text Editor JavaScript is not present.');
     $this->assertTrue(count($field) === 1, 'A text field exists.');
     $this->assertTrue(count($format_selector) === 1, 'A single text format selector exists on the page.');
     $specific_format_selector = $this->xpath('//select[contains(@class, "filter-list") and contains(@class, "editor") and @data-editor-for="edit-field-text-0-value"]');
     $this->assertFalse(count($specific_format_selector) === 1, 'A single text format selector exists on the page and has the "editor" class and a "data-editor-for" attribute with the correct value.');
 }