コード例 #1
0
 /**
  * Tests export of configuration.
  */
 function testExport()
 {
     // Verify the export page with export submit button is available.
     $this->drupalGet('admin/config/development/configuration/full/export');
     $this->assertFieldById('edit-submit', t('Export'));
     // Submit the export form and verify response.
     $this->drupalPostForm('admin/config/development/configuration/full/export', array(), t('Export'));
     $this->assertResponse(200, 'User can access the download callback.');
     // Get the archived binary file provided to user for download.
     $archive_data = $this->drupalGetContent();
     // Temporarily save the archive file.
     $uri = file_unmanaged_save_data($archive_data, 'temporary://config.tar.gz');
     // Extract the archive and verify it's not empty.
     $file_path = file_directory_temp() . '/' . file_uri_target($uri);
     $archiver = new Tar($file_path);
     $archive_contents = $archiver->listContents();
     $this->assert(!empty($archive_contents), 'Downloaded archive file is not empty.');
     // Prepare the list of config files from active storage, see
     // \Drupal\config\Controller\ConfigController::downloadExport().
     $storage_active = $this->container->get('config.storage');
     $config_files = array();
     foreach ($storage_active->listAll() as $config_name) {
         $config_files[] = $config_name . '.yml';
     }
     // Assert that the downloaded archive file contents are the same as the test
     // site active store.
     $this->assertIdentical($archive_contents, $config_files);
     // Ensure the test configuration override is in effect but was not exported.
     $this->assertIdentical(\Drupal::config('system.maintenance')->get('message'), 'Foo');
     $archiver->extract(file_directory_temp(), array('system.maintenance.yml'));
     $file_contents = file_get_contents(file_directory_temp() . '/' . 'system.maintenance.yml');
     $exported = Yaml::decode($file_contents);
     $this->assertNotIdentical($exported['message'], 'Foo');
 }
コード例 #2
0
ファイル: file.api.php プロジェクト: aWEBoLabs/taxi
/**
 * Alter the URL to a file.
 *
 * This hook is called from file_create_url(), and  is called fairly
 * frequently (10+ times per page), depending on how many files there are in a
 * given page.
 * If CSS and JS aggregation are disabled, this can become very frequently
 * (50+ times per page) so performance is critical.
 *
 * This function should alter the URI, if it wants to rewrite the file URL.
 *
 * @param $uri
 *   The URI to a file for which we need an external URL, or the path to a
 *   shipped file.
 */
function hook_file_url_alter(&$uri)
{
    $user = \Drupal::currentUser();
    // User 1 will always see the local file in this example.
    if ($user->id() == 1) {
        return;
    }
    $cdn1 = 'http://cdn1.example.com';
    $cdn2 = 'http://cdn2.example.com';
    $cdn_extensions = array('css', 'js', 'gif', 'jpg', 'jpeg', 'png');
    // Most CDNs don't support private file transfers without a lot of hassle,
    // so don't support this in the common case.
    $schemes = array('public');
    $scheme = file_uri_scheme($uri);
    // Only serve shipped files and public created files from the CDN.
    if (!$scheme || in_array($scheme, $schemes)) {
        // Shipped files.
        if (!$scheme) {
            $path = $uri;
        } else {
            $wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme);
            $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
        }
        // Clean up Windows paths.
        $path = str_replace('\\', '/', $path);
        // Serve files with one of the CDN extensions from CDN 1, all others from
        // CDN 2.
        $pathinfo = pathinfo($path);
        if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], $cdn_extensions)) {
            $uri = $cdn1 . '/' . $path;
        } else {
            $uri = $cdn2 . '/' . $path;
        }
    }
}
コード例 #3
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', 'default') . '/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');
    // Default path for image.
    $hero_path = theme_get_setting('hero_path');
    if (file_uri_scheme($hero_path) == 'public') {
        $hero_path = file_uri_target($hero_path);
    }
    // Helpful text showing the file name, non-editable.
    $form['hero']['hero_path'] = array('#type' => 'textfield', '#title' => 'Path to front page background image', '#default_value' => $hero_path, '#disabled' => TRUE);
    // Upload field.
    $form['hero']['hero_upload'] = array('#type' => 'file', '#title' => 'Upload a new photo for the hero unit', '#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>'), '#upload_validators' => array('file_validate_extensions' => array('png jpg jpeg')));
    // Attach custom submit handler to the form.
    $form['#submit'][] = 'nuboot_radix_settings_submit';
    // Return the additional form widgets.
    return $form;
}
コード例 #4
0
function open_framework_form_system_theme_settings_alter(&$form, &$form_state)
{
    // Responsive Behavior
    $form['responsive_container'] = array('#type' => 'fieldset', '#title' => t('Responsive'), '#description' => t('Use these settings to adjust the responsive behavior.'), '#collapsible' => TRUE, '#collapsed' => FALSE);
    $form['responsive_container']['content_order_classes'] = array('#type' => 'radios', '#title' => t('Content order in mobile'), '#default_value' => theme_get_setting('content_order_classes'), '#options' => array('' => t('Show first sidebar content before main content - <strong><em>Default</em></strong>'), 'content-first ' => t('Show main content before sidebar content')));
    // Page Layout
    $form['layout_container'] = array('#type' => 'fieldset', '#title' => t('Layout'), '#description' => t('Use these settings to adjust the page layout.'), '#collapsible' => TRUE, '#collapsed' => FALSE);
    $form['layout_container']['front_heading_classes'] = array('#type' => 'radios', '#title' => t('Page heading'), '#default_value' => theme_get_setting('front_heading_classes'), '#options' => array('' => t('Hide heading on front page - <strong><em>Default</em></strong>'), 'show-title ' => t('Show heading on front page')));
    $form['layout_container']['breadcrumb_classes'] = array('#type' => 'radios', '#title' => t('Breadcrumbs'), '#default_value' => theme_get_setting('breadcrumb_classes'), '#options' => array('' => t('Hide breadcrumbs - <strong><em>Default</em></strong>'), 'show-breadcrumb ' => t('Show breadcrumbs')));
    // Background Section
    $form['background_container'] = array('#type' => 'fieldset', '#title' => t('Background Images'), '#description' => t('Use these settings to select different background images.'), '#collapsible' => TRUE, '#collapsed' => FALSE);
    // Body Background Image
    $form['background_container']['body_bg_type'] = array('#type' => 'radios', '#title' => t('Body background image type'), '#default_value' => theme_get_setting('body_bg_type'), '#options' => array('' => t('Wallpaper pattern - <strong><em>Default</em></strong>'), 'photobg ' => t('Photo image')));
    $form['background_container']['body_bg_classes'] = array('#type' => 'radios', '#title' => t('Body background image'), '#default_value' => theme_get_setting('body_bg_classes'), '#options' => array('' => t('None - <strong><em>Default</em></strong>'), 'bodybg ' => t('Use my image (upload below):')));
    // Default path for image
    $body_bg_path = theme_get_setting('body_bg_path');
    if (file_uri_scheme($body_bg_path) == 'public') {
        $body_bg_path = file_uri_target($body_bg_path);
    }
    // Helpful text showing the file name, disabled to avoid the user thinking it can be used for any purpose.
    $form['background_container']['body_bg_path'] = array('#type' => 'hidden', '#title' => 'Path to background image', '#default_value' => $body_bg_path);
    if (!empty($body_bg_path)) {
        $form['background_container']['body_bg_preview'] = array('#markup' => !empty($body_bg_path) ? theme('image', array('path' => theme_get_setting('body_bg_path'))) : '');
    }
    // Upload field
    $form['background_container']['body_bg_upload'] = array('#type' => 'file', '#title' => 'Upload background image', '#description' => 'You can upload the following image file types: *.jpg, *.gif, or *.png');
    // Border Style
    $form['border_container'] = array('#type' => 'fieldset', '#title' => t('Borders'), '#description' => t('Use these settings to change the border style.'), '#collapsible' => TRUE, '#collapsed' => FALSE);
    $form['border_container']['border_classes'] = array('#type' => 'radios', '#title' => t('Border style for content section'), '#default_value' => theme_get_setting('border_classes'), '#options' => array('' => t('No borders - <strong><em>Default</em></strong>'), 'borders' => t('Show borders')));
    $form['border_container']['corner_classes'] = array('#type' => 'radios', '#title' => t('Corner style'), '#default_value' => theme_get_setting('corner_classes'), '#options' => array('' => t('Straight corners - <strong><em>Default</em></strong>'), 'roundedcorners' => t('Rounded corners (not supported in Internet Explorer 8 or below)')));
    // Attach custom submit handler to the form
    $form['#submit'][] = 'open_framework_settings_submit';
    $form['#validate'][] = 'open_framework_settings_validate';
}
コード例 #5
0
 /**
  * Test the getViaUri() and getViaScheme() methods and target functions.
  */
 function testUriFunctions()
 {
     $config = $this->config('system.file');
     $instance = \Drupal::service('stream_wrapper_manager')->getViaUri($this->scheme . '://foo');
     $this->assertEqual($this->classname, get_class($instance), 'Got correct class type for dummy URI.');
     $instance = \Drupal::service('stream_wrapper_manager')->getViaUri('public://foo');
     $this->assertEqual('Drupal\\Core\\StreamWrapper\\PublicStream', get_class($instance), 'Got correct class type for public URI.');
     // Test file_uri_target().
     $this->assertEqual(file_uri_target('public://foo/bar.txt'), 'foo/bar.txt', 'Got a valid stream target from public://foo/bar.txt.');
     $this->assertEqual(file_uri_target('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='), 'image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', t('Got a valid stream target from a data URI.'));
     $this->assertFalse(file_uri_target('foo/bar.txt'), 'foo/bar.txt is not a valid stream.');
     $this->assertFalse(file_uri_target('public://'), 'public:// has no target.');
     $this->assertFalse(file_uri_target('data:'), 'data: has no target.');
     // Test file_build_uri() and
     // Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath().
     $this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', 'Expected scheme was added.');
     $this->assertEqual(\Drupal::service('stream_wrapper_manager')->getViaScheme('public')->getDirectoryPath(), PublicStream::basePath(), 'Expected default directory path was returned.');
     $this->assertEqual(\Drupal::service('stream_wrapper_manager')->getViaScheme('temporary')->getDirectoryPath(), $config->get('path.temporary'), 'Expected temporary directory path was returned.');
     $config->set('default_scheme', 'private')->save();
     $this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', 'Got a valid URI from foo/bar.txt.');
     // Test file_create_url()
     // TemporaryStream::getExternalUrl() uses Url::fromRoute(), which needs
     // route information to work.
     $this->container->get('router.builder')->rebuild();
     $this->assertTrue(strpos(file_create_url('temporary://test.txt'), 'system/temporary?file=test.txt'), 'Temporary external URL correctly built.');
     $this->assertTrue(strpos(file_create_url('public://test.txt'), Settings::get('file_public_path') . '/test.txt'), 'Public external URL correctly built.');
     $this->assertTrue(strpos(file_create_url('private://test.txt'), 'system/files/test.txt'), 'Private external URL correctly built.');
 }
コード例 #6
0
ファイル: ThemeTest.php プロジェクト: nstielau/drops-8
 /**
  * Test the theme settings form.
  */
 function testThemeSettings()
 {
     // Ensure invalid theme settings form URLs return a proper 404.
     $this->drupalGet('admin/appearance/settings/bartik');
     $this->assertResponse(404, 'The theme settings form URL for a uninstalled theme could not be found.');
     $this->drupalGet('admin/appearance/settings/' . $this->randomMachineName());
     $this->assertResponse(404, 'The theme settings form URL for a non-existent theme could not be found.');
     // Specify a filesystem path to be used for the logo.
     $file = current($this->drupalGetTestFiles('image'));
     $file_relative = strtr($file->uri, array('public:/' => PublicStream::basePath()));
     $default_theme_path = 'core/themes/classy';
     $supported_paths = array($file->uri => array('form' => file_uri_target($file->uri), 'src' => file_create_url($file->uri)), file_uri_target($file->uri) => array('form' => file_uri_target($file->uri), 'src' => file_create_url($file->uri)), $file_relative => array('form' => $file_relative, 'src' => file_create_url($file->uri)), 'core/misc/druplicon.png' => array('form' => 'core/misc/druplicon.png', 'src' => $GLOBALS['base_url'] . '/' . 'core/misc/druplicon.png'), $default_theme_path . '/logo.svg' => array('form' => $default_theme_path . '/logo.svg', 'src' => $GLOBALS['base_url'] . '/' . $default_theme_path . '/logo.svg'));
     foreach ($supported_paths as $input => $expected) {
         $edit = array('default_logo' => FALSE, 'logo_path' => $input);
         $this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration'));
         $this->assertNoText('The custom logo path is invalid.');
         $this->assertFieldByName('logo_path', $expected['form']);
         // Verify logo path examples.
         $elements = $this->xpath('//div[contains(@class, :item)]/div[@class=:description]/code', array(':item' => 'form-item-logo-path', ':description' => 'description'));
         // Expected default values (if all else fails).
         $implicit_public_file = 'logo.svg';
         $explicit_file = 'public://logo.svg';
         $local_file = $default_theme_path . '/logo.svg';
         // Adjust for fully qualified stream wrapper URI in public filesystem.
         if (file_uri_scheme($input) == 'public') {
             $implicit_public_file = file_uri_target($input);
             $explicit_file = $input;
             $local_file = strtr($input, array('public:/' => PublicStream::basePath()));
         } elseif (file_uri_scheme($input) !== FALSE) {
             $explicit_file = $input;
         } elseif ($input == file_uri_target($file->uri)) {
             $implicit_public_file = $input;
             $explicit_file = 'public://' . $input;
             $local_file = PublicStream::basePath() . '/' . $input;
         }
         $this->assertEqual((string) $elements[0], $implicit_public_file);
         $this->assertEqual((string) $elements[1], $explicit_file);
         $this->assertEqual((string) $elements[2], $local_file);
         // Verify the actual 'src' attribute of the logo being output.
         $this->drupalGet('');
         $elements = $this->xpath('//header/a[@rel=:rel]/img', array(':rel' => 'home'));
         $this->assertEqual((string) $elements[0]['src'], $expected['src']);
     }
     $unsupported_paths = array('public://whatever.png', 'private://whatever.png', 'temporary://whatever.png', 'public:/whatever.png', '://whatever.png', ':whatever.png', 'public://', 'whatever.png', PublicStream::basePath() . '/whatever.png', '/' . PublicStream::basePath() . '/whatever.png', 'core/misc/whatever.png', '/core/misc/whatever.png', drupal_realpath($file->uri));
     $this->drupalGet('admin/appearance/settings');
     foreach ($unsupported_paths as $path) {
         $edit = array('default_logo' => FALSE, 'logo_path' => $path);
         $this->drupalPostForm(NULL, $edit, t('Save configuration'));
         $this->assertText('The custom logo path is invalid.');
     }
     // Upload a file to use for the logo.
     $edit = array('default_logo' => FALSE, 'logo_path' => '', 'files[logo_upload]' => drupal_realpath($file->uri));
     $this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration'));
     $fields = $this->xpath($this->constructFieldXpath('name', 'logo_path'));
     $uploaded_filename = 'public://' . $fields[0]['value'];
     $this->drupalGet('');
     $elements = $this->xpath('//header/a[@rel=:rel]/img', array(':rel' => 'home'));
     $this->assertEqual($elements[0]['src'], file_create_url($uploaded_filename));
 }
コード例 #7
0
 /**
  * Tests export of configuration.
  */
 function testExport()
 {
     // Verify the export page with export submit button is available.
     $this->drupalGet('admin/config/development/configuration/full/export');
     $this->assertFieldById('edit-submit', t('Export'));
     // Submit the export form and verify response.
     $this->drupalPostForm('admin/config/development/configuration/full/export', array(), t('Export'));
     $this->assertResponse(200, 'User can access the download callback.');
     // Test if header contains file name with hostname and timestamp.
     $request = \Drupal::request();
     $hostname = str_replace('.', '-', $request->getHttpHost());
     $header_content_disposition = $this->drupalGetHeader('content-disposition');
     $header_match = (bool) preg_match('/attachment; filename="config-' . preg_quote($hostname) . '-\\d{4}-\\d{2}-\\d{2}-\\d{2}-\\d{2}\\.tar\\.gz"/', $header_content_disposition);
     $this->assertTrue($header_match, "Header with filename matches the expected format.");
     // Get the archived binary file provided to user for download.
     $archive_data = $this->getRawContent();
     // Temporarily save the archive file.
     $uri = file_unmanaged_save_data($archive_data, 'temporary://config.tar.gz');
     // Extract the archive and verify it's not empty.
     $file_path = file_directory_temp() . '/' . file_uri_target($uri);
     $archiver = new Tar($file_path);
     $archive_contents = $archiver->listContents();
     $this->assert(!empty($archive_contents), 'Downloaded archive file is not empty.');
     // Prepare the list of config files from active storage, see
     // \Drupal\config\Controller\ConfigController::downloadExport().
     $storage_active = $this->container->get('config.storage');
     $config_files = array();
     foreach ($storage_active->listAll() as $config_name) {
         $config_files[] = $config_name . '.yml';
     }
     // Assert that the downloaded archive file contents are the same as the test
     // site active store.
     $this->assertIdentical($archive_contents, $config_files);
     // Ensure the test configuration override is in effect but was not exported.
     $this->assertIdentical(\Drupal::config('system.maintenance')->get('message'), 'Foo');
     $archiver->extract(file_directory_temp(), array('system.maintenance.yml'));
     $file_contents = file_get_contents(file_directory_temp() . '/' . 'system.maintenance.yml');
     $exported = Yaml::decode($file_contents);
     $this->assertNotIdentical($exported['message'], 'Foo');
     // Check the single export form doesn't have "form-required" elements.
     $this->drupalGet('admin/config/development/configuration/single/export');
     $this->assertNoRaw('js-form-required form-required', 'No form required fields are found.');
     // Ensure the temporary file is not available to users without the
     // permission.
     $this->drupalLogout();
     $this->drupalGet('system/temporary', ['query' => ['file' => 'config.tar.gz']]);
     $this->assertResponse(403);
 }
コード例 #8
0
ファイル: theme-settings.php プロジェクト: EWB/grh
function academy_form_system_theme_settings_alter(&$form, &$form_state)
{
    // Container fieldset
    $form['bg_image'] = array('#type' => 'fieldset', '#title' => t('Background image (must be tileable PNG)'));
    // Default path for image
    $bg_path = theme_get_setting('bg_path');
    if (file_uri_scheme($bg_path) == 'public') {
        $bg_path = file_uri_target($bg_path);
    }
    // Helpful text showing the file name, disabled to avoid the user thinking it can be used for any purpose.
    $form['bg_image']['bg_path'] = array('#type' => 'textfield', '#title' => 'Path to background image', '#default_value' => $bg_path, '#disabled' => TRUE);
    // Upload field
    $form['bg_image']['bg_upload'] = array('#type' => 'file', '#title' => 'Upload background image', '#description' => 'Upload a new image for the background.');
    // Attach custom submit handler to the form
    $form['#submit'][] = 'academy_settings_submit';
}
コード例 #9
0
/**
 * Implements hook_form_system_theme_settings_alter().
 */
function nuboot_form_system_theme_settings_alter(&$form, &$form_state)
{
    // Hero fieldset.
    $form['hero'] = array('#type' => 'fieldset', '#title' => t('Hero Unit'), '#group' => 'general');
    // Default path for image.
    $hero_path = theme_get_setting('hero_path');
    if (file_uri_scheme($hero_path) == 'public') {
        $hero_path = file_uri_target($hero_path);
    }
    // Helpful text showing the file name, non-editable.
    $form['hero']['hero_path'] = array('#type' => 'textfield', '#title' => 'Path to front page hero unit background image', '#default_value' => $hero_path, '#disabled' => TRUE);
    // Upload field.
    $form['hero']['hero_upload'] = array('#type' => 'file', '#title' => 'Upload a photo for the hero unit background image', '#description' => 'Upload a new image for the hero region background.', '#upload_validators' => array('file_validate_extensions' => array('png jpg jpeg')));
    // Attach custom submit handler to the form.
    $form['#submit'][] = 'nuboot_settings_submit';
}
コード例 #10
0
ファイル: theme-settings.php プロジェクト: ehazell/AZDWR
function agency_1_form_system_theme_settings_alter(&$form, &$form_state)
{
    //Add the css to fix the color module's goofy form
    drupal_add_css(drupal_get_path('theme', 'agency_1') . '/css/colors-admin.css');
    //Fix color module rendering of new colors added to .inc file
    agency_1_theme_settings_add_new_colors();
    /*
     * Sliver show/hide
     */
    $show_sliver = isset($theme_settings['show_sliver']) ? $theme_settings['show_sliver'] : NULL;
    //Add the checkbox to the form
    $form['sliver'] = array('#type' => 'fieldset', '#title' => t('Sliver banner settings'), '#description' => t('If toggled on, the sliver banner will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['sliver']['show_sliver'] = array('#type' => 'checkbox', '#title' => t('Display the sliver banner'), '#default_value' => theme_get_setting('show_sliver'), '#tree' => FALSE, '#description' => t('Check here if you want the theme to display the sliver banner.'));
    /*
     * Background Image
     */
    $background_path = isset($theme_settings['background_path']) ? $theme_settings['background_path'] : NULL;
    // If $background_path is a public:// URI, display the path relative to the files directory. (Stream wrappers are not end-user friendly)
    if (file_uri_scheme($background_path) == 'public') {
        $background_path = file_uri_target($background_path);
    }
    //Add the background image fields to the form
    $form['background_image'] = array('#type' => 'fieldset', '#title' => t('Background image settings'), '#description' => t('If toggled on, the following background will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['background_image']['default_background'] = array('#type' => 'checkbox', '#title' => t('Use the default background'), '#default_value' => theme_get_setting('default_background'), '#tree' => FALSE, '#description' => t('Check here if you want the theme to use the background supplied with it.'));
    $form['background_image']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="default_background"]' => array('checked' => TRUE))));
    $form['background_image']['settings']['background_path'] = array('#type' => 'textfield', '#title' => t('Path to custom background'), '#description' => t('The path to the file you would like to use as your background file instead of the default background.'), '#default_value' => theme_get_setting('background_path'));
    $form['background_image']['settings']['background_file'] = array('#type' => 'file', '#title' => t('Upload background image'), '#maxlength' => 40, '#description' => t("If you don't have direct file access to the server, use this field to upload your background image."), '#element_validate' => array('_agency_1_theme_settings_validate'));
    //Toggle display of the branding block in the footer
    $form['footer_branding'] = array('#type' => 'fieldset', '#title' => t('Footer Branding settings'), '#description' => t('If toggled on, the branding block will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['footer_branding']['display_footer_branding'] = array('#type' => 'checkbox', '#title' => t('Display the branding block in the footer'), '#default_value' => theme_get_setting('display_footer_branding'), '#tree' => FALSE, '#description' => t('Check here if you want to display the branding  block in the footer.'));
    //Capture the information for the Contact Us section in the footer
    $form['footer_contact_us'] = array('#type' => 'fieldset', '#title' => t('Footer "Contact Us" settings'), '#description' => t('If toggled on, the Contact Us block will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['footer_contact_us']['display_footer_contact'] = array('#type' => 'checkbox', '#title' => t('Display the Contact Us block in the footer'), '#default_value' => theme_get_setting('display_footer_contact'), '#tree' => FALSE, '#description' => t('Check here if you want to display the Contact Us block in the footer.'));
    $form['footer_contact_us']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="display_footer_contact"]' => array('checked' => FALSE))));
    $form['footer_contact_us']['settings']['footer_contact_us_title'] = array('#type' => 'textfield', '#title' => t('Title'), '#description' => t('Title for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_title'));
    $form['footer_contact_us']['settings']['footer_contact_us_title_link'] = array('#type' => 'textfield', '#title' => t('Title Link'), '#description' => t('Link for the title in the Contact Us block. (Recommend linking to the contact form.)'), '#default_value' => theme_get_setting('footer_contact_us_title_link'));
    $form['footer_contact_us']['settings']['footer_contact_us_agency_title'] = array('#type' => 'textfield', '#title' => t('Agency Title'), '#description' => t('Agency title for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_agency_title'));
    $form['footer_contact_us']['settings']['footer_contact_us_address_1'] = array('#type' => 'textfield', '#title' => t('Address Line 1'), '#description' => t('Address line 1 for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_address_1'));
    $form['footer_contact_us']['settings']['footer_contact_us_address_2'] = array('#type' => 'textfield', '#title' => t('Address Line 2'), '#description' => t('Address line 2 for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_address_2'));
    $form['footer_contact_us']['settings']['footer_contact_us_phone'] = array('#type' => 'textfield', '#title' => t('Phone Number'), '#description' => t('Phone number for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_phone'));
    $form['footer_contact_us']['settings']['footer_contact_us_fax'] = array('#type' => 'textfield', '#title' => t('Fax Number'), '#description' => t('Fax number for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_fax'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_link'] = array('#type' => 'textfield', '#title' => t('Map Link'), '#description' => t('Link for the map in the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_map_link'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_path'] = array('#type' => 'textfield', '#title' => t('Path to map image'), '#description' => t('The path to the file you would like to use as your map image. (150px x 150px)'), '#default_value' => theme_get_setting('footer_contact_us_map_path'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_image'] = array('#type' => 'file', '#title' => t('Upload map image'), '#maxlength' => 40, '#description' => t("Use this field to upload your map image. (150px x 150px.  Will be resized if necessary.)"), '#element_validate' => array('_agency_1_theme_settings_map'));
    //End Contact Us
    return $form;
}
コード例 #11
0
/**
 * Implementation of hook_form_system_theme_settings_alter() 
 */
function locke_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', 'locke') . '/theme-settings.php';
    // Add theme settings here.
    $form['locke_theme_settings'] = array('#title' => t('Theme Settings'), '#type' => 'fieldset');
    // Copyright.
    $copyright = theme_get_setting('copyright');
    $form['locke_theme_settings']['copyright'] = array('#title' => t('Copyright'), '#type' => 'text_format', '#format' => $copyright['format'], '#default_value' => $copyright['value'] ? $copyright['value'] : t('Drupal is a registered trademark of Dries Buytaert.'));
    // Update the "Toogle Display" to something clearer
    $form['theme_settings']['#title'] = t('Theme Display Settings');
    // Change Weighting of Default Setting Fields
    $form['theme_settings']['#weight'] = 20;
    $form['logo']['#weight'] = 30;
    $form['favicon']['#weight'] = 40;
    // Define the contact information fieldset
    $form['contact_information'] = array('#type' => 'fieldset', '#title' => t('Contact Information in Footer'));
    // Define the phone number
    $form['contact_information']['phone'] = array('#type' => 'textfield', '#title' => t('Phone Number'), '#default_value' => theme_get_setting('phone'));
    // Define your fax number
    $form['contact_information']['fax'] = array('#type' => 'textfield', '#title' => t('Fax Number'), '#default_value' => theme_get_setting('fax'));
    // Define your address
    $form['contact_information']['address'] = array('#type' => 'textarea', '#title' => t('Address'), '#rows' => 3, '#default_value' => theme_get_setting('address'));
    // Define the social media links
    $form['social_media'] = array('#type' => 'fieldset', '#title' => t('Social Media Links in Footer'));
    // Define the twitter link
    $form['social_media']['twitter_link'] = array('#type' => 'textfield', '#title' => 'Twitter', '#default_value' => theme_get_setting('twitter_link'));
    // Define the facebook link
    $form['social_media']['facebook_link'] = array('#type' => 'textfield', '#title' => 'Facebook', '#default_value' => theme_get_setting('facebook_link'));
    // Define the youtube link
    $form['social_media']['youtube_link'] = array('#type' => 'textfield', '#title' => 'YouTube', '#default_value' => theme_get_setting('youtube_link'));
    // Update the image settings to include seal
    $form['logo']['#title'] = 'Image settings';
    $default_seal = theme_get_setting('default_seal');
    $form['logo']['default_seal'] = array('#type' => 'checkbox', '#title' => t('Use the default seal'), '#tree' => FALSE, '#description' => t('Check here if you want the theme to use the seal supplied with it'), '#default_value' => empty($default_seal) ? 0 : 1);
    $seal_path = theme_get_setting('seal_path');
    // If $seal_path is a public:// URI, display the path relative to the files
    // directory; stream wrappers are not end-user friendly.
    if (file_uri_scheme($seal_path) == 'public') {
        $seal_path = file_uri_target($seal_path);
    }
    $form['logo']['seal_settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="default_seal"]' => array('checked' => TRUE))), 'seal_path' => array('#type' => 'textfield', '#title' => 'Path to custom seal', '#description' => 'The path to the file you would like to use as your seal file instead of the default seal.', '#default_value' => $seal_path), 'seal_upload' => array('#type' => 'file', '#title' => 'Upload logo image', '#maxlength' => 40, '#description' => 'If you don\'t have direct file access to the server, use this field to upload your seal.'));
    $form['#submit'][] = 'locke_theme_settings_submit';
    $form['#validate'][] = 'locke_theme_settings_validate';
}
コード例 #12
0
 /**
  * Test the URI and target functions.
  */
 function testUriFunctions()
 {
     $config = \Drupal::config('system.file');
     $instance = file_stream_wrapper_get_instance_by_uri($this->scheme . '://foo');
     $this->assertEqual($this->classname, get_class($instance), 'Got correct class type for dummy URI.');
     $instance = file_stream_wrapper_get_instance_by_uri('public://foo');
     $this->assertEqual('Drupal\\Core\\StreamWrapper\\PublicStream', get_class($instance), 'Got correct class type for public URI.');
     // Test file_uri_target().
     $this->assertEqual(file_uri_target('public://foo/bar.txt'), 'foo/bar.txt', 'Got a valid stream target from public://foo/bar.txt.');
     $this->assertFalse(file_uri_target('foo/bar.txt'), 'foo/bar.txt is not a valid stream.');
     // Test file_build_uri() and
     // Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath().
     $this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', 'Expected scheme was added.');
     $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), PublicStream::basePath(), 'Expected default directory path was returned.');
     $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), $config->get('path.temporary'), 'Expected temporary directory path was returned.');
     $config->set('default_scheme', 'private')->save();
     $this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', 'Got a valid URI from foo/bar.txt.');
 }
コード例 #13
0
 /**
  * Test the URI and target functions.
  */
 function testUriFunctions()
 {
     $config = \Drupal::config('system.file');
     $instance = file_stream_wrapper_get_instance_by_uri($this->scheme . '://foo');
     $this->assertEqual($this->classname, get_class($instance), 'Got correct class type for dummy URI.');
     $instance = file_stream_wrapper_get_instance_by_uri('public://foo');
     $this->assertEqual('Drupal\\Core\\StreamWrapper\\PublicStream', get_class($instance), 'Got correct class type for public URI.');
     // Test file_uri_target().
     $this->assertEqual(file_uri_target('public://foo/bar.txt'), 'foo/bar.txt', 'Got a valid stream target from public://foo/bar.txt.');
     $this->assertEqual(file_uri_target('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='), 'image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', t('Got a valid stream target from a data URI.'));
     $this->assertFalse(file_uri_target('foo/bar.txt'), 'foo/bar.txt is not a valid stream.');
     $this->assertFalse(file_uri_target('public://'), 'public:// has no target.');
     $this->assertFalse(file_uri_target('data:'), 'data: has no target.');
     // Test file_build_uri() and
     // Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath().
     $this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', 'Expected scheme was added.');
     $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), PublicStream::basePath(), 'Expected default directory path was returned.');
     $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), $config->get('path.temporary'), 'Expected temporary directory path was returned.');
     $config->set('default_scheme', 'private')->save();
     $this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', 'Got a valid URI from foo/bar.txt.');
 }
コード例 #14
0
 /**
  * Tests embedded users on node pages.
  */
 function testPictureOnNodeComment()
 {
     $this->drupalLogin($this->web_user);
     // Save a new picture.
     $image = current($this->drupalGetTestFiles('image'));
     $file = $this->saveUserPicture($image);
     $node = $this->drupalCreateNode(array('type' => 'article'));
     // Enable user pictures on nodes.
     $this->container->get('config.factory')->get('system.theme.global')->set('features.node_user_picture', TRUE)->save();
     // Verify that the image is displayed on the user account page.
     $this->drupalGet('node/' . $node->id());
     $this->assertRaw(file_uri_target($file->getFileUri()), 'User picture found on node page.');
     // Enable user pictures on comments, instead of nodes.
     $this->container->get('config.factory')->get('system.theme.global')->set('features.node_user_picture', FALSE)->set('features.comment_user_picture', TRUE)->save();
     $edit = array('comment_body[0][value]' => $this->randomString());
     $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Save'));
     $this->assertRaw(file_uri_target($file->getFileUri()), 'User picture found on comment.');
     // Disable user pictures on comments and nodes.
     $this->container->get('config.factory')->get('system.theme.global')->set('features.node_user_picture', FALSE)->set('features.comment_user_picture', FALSE)->save();
     \Drupal::entityManager()->getViewBuilder('comment')->resetCache();
     $this->drupalGet('node/' . $node->id());
     $this->assertNoRaw(file_uri_target($file->getFileUri()), 'User picture not found on node and comment.');
 }
コード例 #15
0
function hosting_form_system_theme_settings_alter(&$form, &$form_state)
{
    $contact_icon = theme_get_setting('contact_icon');
    if (file_uri_scheme($contact_icon) == 'public') {
        $contact_icon = file_uri_target($contact_icon);
    }
    drupal_add_css(drupal_get_path('theme', 'hosting') . '/css/theme-settings.css');
    // Contact
    $form['contact'] = array('#type' => 'fieldset', '#title' => 'Contact Setting', '#group' => 'drupaloss_settings', '#weight' => 100);
    // Contact MAP
    /*
    $form['contact']['contactmap'] = array(
        '#type' => 'fieldset',
        '#title' => '<div class="plus"></div><h3 class="options_heading">Contact Map</h3>',
    );
    */
    // Contact MAP Address
    $contact_address = theme_get_setting('contact_address');
    $form['contact']['contact_address'] = array('#type' => 'text_format', '#title' => t('Company Address'), '#default_value' => isset($contact_address['value']) ? $contact_address['value'] : '', '#format' => isset($contact_address['format']) ? $contact_address['format'] : 'filtered_html');
    // Contact MAP Phone
    $form['contact']['contact_phone'] = array('#type' => 'textfield', '#title' => t('Company Telephone'), '#default_value' => theme_get_setting('contact_phone'));
    // Company Name
    $form['contact']['contact_mail'] = array('#type' => 'textfield', '#title' => t('Company Email'), '#default_value' => theme_get_setting('contact_mail'));
    // Website
    $form['contact']['contact_website'] = array('#type' => 'textfield', '#title' => 'Website', '#default_value' => theme_get_setting('contact_website'));
    // Contact MAP Lat
    $form['contact']['contactmap_lat'] = array('#type' => 'textfield', '#title' => 'Lat', '#description' => t('Lat google map'), '#default_value' => theme_get_setting('contactmap_lat'));
    // Contact MAP Long
    $form['contact']['contactmap_long'] = array('#type' => 'textfield', '#title' => 'Long', '#description' => t('Long google map'), '#default_value' => theme_get_setting('contactmap_long'));
    $form['contact']['contact_icon'] = array('#type' => 'textfield', '#title' => 'Path to Contact Icon', '#default_value' => $contact_icon, '#disabled' => TRUE);
    $form['contact']['contact_icon_upload'] = array('#type' => 'file', '#title' => 'Upload maker icon', '#description' => 'Google map maker icon.');
    $form['contact']['style_map_google'] = array('#type' => 'textarea', '#title' => 'Style map google', '#description' => 'Copy code map google "Javascript style array" in web ' . l('Style google', 'http://snazzymaps.com/', array('attributes' => array('target' => '_blank'))), '#rows' => 20, '#default_value' => theme_get_setting('style_map_google'));
    $text_map = theme_get_setting('text_map_tip');
    $form['contact']['text_map_tip'] = array('#type' => 'text_format', '#title' => t('Text Map'), '#default_value' => isset($text_map['value']) ? $text_map['value'] : '', '#description' => t('This text show tip on map'), '#format' => isset($text_map['format']) ? $text_map['format'] : 'filtered_html');
    // Submit Button
    $form['#submit'][] = 'hosting_themes_settings_submit';
}
コード例 #16
0
ファイル: UserPictureTest.php プロジェクト: sarahwillem/OD8
 /**
  * Tests embedded users on node pages.
  */
 function testPictureOnNodeComment()
 {
     $this->drupalLogin($this->webUser);
     // Save a new picture.
     $image = current($this->drupalGetTestFiles('image'));
     $file = $this->saveUserPicture($image);
     $node = $this->drupalCreateNode(array('type' => 'article'));
     // Enable user pictures on nodes.
     $this->config('system.theme.global')->set('features.node_user_picture', TRUE)->save();
     $image_style_id = $this->config('core.entity_view_display.user.user.compact')->get('content.user_picture.settings.image_style');
     $style = ImageStyle::load($image_style_id);
     $image_url = $style->buildUrl($file->getfileUri());
     $alt_text = 'Profile picture for user ' . $this->webUser->getUsername();
     // Verify that the image is displayed on the node page.
     $this->drupalGet('node/' . $node->id());
     $elements = $this->cssSelect('.node__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]');
     $this->assertEqual(count($elements), 1, 'User picture with alt text found on node page.');
     // Enable user pictures on comments, instead of nodes.
     $this->config('system.theme.global')->set('features.node_user_picture', FALSE)->set('features.comment_user_picture', TRUE)->save();
     $edit = array('comment_body[0][value]' => $this->randomString());
     $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Save'));
     $elements = $this->cssSelect('.comment__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]');
     $this->assertEqual(count($elements), 1, 'User picture with alt text found on the comment.');
     // Disable user pictures on comments and nodes.
     $this->config('system.theme.global')->set('features.node_user_picture', FALSE)->set('features.comment_user_picture', FALSE)->save();
     $this->drupalGet('node/' . $node->id());
     $this->assertNoRaw(file_uri_target($file->getFileUri()), 'User picture not found on node and comment.');
 }
コード例 #17
0
ファイル: FeedsEnclosure.php プロジェクト: Tawreh/mtg
 /**
  * Returns a Drupal file object of the enclosed resource.
  *
  * @param string $destination
  *   The path or uri specifying the target directory in which the file is
  *   expected. Don't use trailing slashes unless it's a streamwrapper scheme.
  * @param int $replace
  *   (optional) Replace behavior when the destination file already exists:
  *   - FILE_EXISTS_REPLACE - Replace the existing file. If a managed file with
  *       the destination name exists then its database entry will be updated.
  *       If no database entry is found then a new one will be created.
  *   - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename
  *       is unique.
  *   - FILE_EXISTS_ERROR - Do nothing and return FALSE.
  *   Defaults to FILE_EXISTS_RENAME.
  *
  * @return \Drupal\file\Entity\FileInterface
  *   A Drupal temporary file object of the enclosed resource.
  *
  * @throws \RuntimeException
  *   If file object could not be created.
  *
  * @todo Refactor this
  */
 public function getFile($destination, $replace = FILE_EXISTS_RENAME)
 {
     $file = FALSE;
     if (!$this->uri) {
         return $file;
     }
     // Prepare destination directory.
     file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY);
     // Copy or save file depending on whether it is remote or local.
     if (drupal_realpath($this->uri)) {
         $file = entity_create('file', ['uid' => 0, 'uri' => $this->uri, 'filemime' => $this->mimeType, 'filename' => basename($this->uri)]);
         if (drupal_dirname($file->getFileUri()) != $destination) {
             $file = file_copy($file, $destination, $replace);
         } else {
             // If file is not to be copied, check whether file already exists,
             // as file_save() won't do that for us (compare file_copy() and
             // file_save())
             $existing_files = file_load_multiple([], ['uri' => $file->getFileUri()]);
             if ($existing_files) {
                 return reset($existing_files);
             }
             $file->save();
         }
     } else {
         $filename = drupal_basename($this->uri);
         if (\Drupal::moduleHandler()->moduleExists('transliteration')) {
             require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
             $filename = transliteration_clean_filename($filename);
         }
         if (file_uri_target($destination)) {
             $destination = trim($destination, '/') . '/';
         }
         try {
             $file = file_save_data($this->getContent(), $destination . $filename, $replace);
         } catch (\Exception $e) {
             watchdog_exception('Feeds', $e, nl2br(SafeMarkup::checkPlain($e)));
         }
     }
     // We couldn't make sense of this enclosure, throw an exception.
     if (!$file) {
         throw new \RuntimeException(SafeMarkup::format('Invalid enclosure %enclosure', ['%enclosure' => $this->uri]));
     }
     return $file;
 }
コード例 #18
0
/**
 * Updates the file entry in file_managed in Drupal to the new uri.
 *
 * @param string $file
 *   The file path.
 */
function updateDrupalFile($file)
{
    if (!file_exists($file->pdf)) {
        return FALSE;
    }
    //Default stream / filepath
    $streams = array('public://');
    $path = 'sites/default/files/';
    if (defined('DRUPAL_CUSTOM_STREAM_WRAPPER')) {
        $wrapper = file_stream_wrapper_get_instance_by_uri(DRUPAL_CUSTOM_STREAM_WRAPPER);
        $path = $wrapper->getDirectoryPath() . "/" . file_uri_target($uri);
        $streams[] = DRUPAL_CUSTOM_STREAM_WRAPPER;
    }
    $file_parts = explode($path, $file->file);
    if (!isset($file_parts[1])) {
        return FALSE;
    }
    $uris = array();
    foreach ($streams as $stream) {
        $uris[] = $stream . $file_parts[1];
    }
    $uris[] = $file->file;
    $query = db_query('SELECT f.fid, f.uri
                      FROM {file_managed} f
                      WHERE f.uri IN (:uris)', array(':uris' => $uris));
    $d_file = $query->fetchAssoc();
    if ($d_file) {
        db_update('file_managed')->fields(array('filename' => basename($file->pdf), 'uri' => preg_replace('/\\.(' . implode('|', PDFConverter::getAllowedExtenstions()) . ')$/i', '.pdf', $d_file['uri']), 'filemime' => 'application/pdf', 'filesize' => filesize($file->pdf), 'timestamp' => time(), 'type' => 'document'))->condition('fid', $d_file['fid'])->execute();
    }
}
コード例 #19
0
ファイル: theme-settings.php プロジェクト: nerdhaus/singular
/**
 * Implements hook_form_system_theme_settings_alter() for themes.
 */
function singular_form_system_theme_settings_alter(&$form, &$form_state) {
  include_once(drupal_get_path('theme', 'singular') .'/styles.inc');
  $base = drupal_get_path('theme', 'singular');

  $form['singular_container'] = array(
    '#type' => 'fieldset',
    '#title' => t('Singular theme settings'),
  );

  $form['singular_container']['layout'] = array(
    '#title' => t('Layout'),
    '#type' => 'select',
    '#options' => array('fixed' => t('Fixed width'), 'fluid' => t('Fluid width')),
    '#default_value' => theme_get_setting('layout'),
  );

  $form['singular_container']['messages']['autoclose'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Autoclose messages'),
    '#options' => array('status' => t('Status'), 'warning' => t('Warning'), 'error' => t('Error')),
    '#default_value' => theme_get_setting('autoclose'),
    '#description' => t('Select the message types to close automatically after a few seconds.'),
  );

  $form['singular_container']['style'] = array(
    '#title' => t('Styles'),
    '#type' => 'select',
    '#options' => singular_get_styles(),
    '#default_value' => theme_get_setting('style'),
  );

  $form['singular_container']['custom'] = array(
    '#type' => 'container',
    '#states' => array(
      'visible' => array(
        ':input[name=style]' => array('value' => 'custom'),
      ),
    ),
  );
  $background_path = theme_get_setting('background_path');
  // If $background_path is a public:// URI, display the path relative to the files
  // directory; stream wrappers are not end-user friendly.
  if (file_uri_scheme($background_path) == 'public') {
    $background_path = file_uri_target($background_path);
  }
  $form['singular_container']['custom']['background_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to custom background'),
    '#default_value' => $background_path,
    '#description' => t('The path to the file you would like to use as your background image.'),
  );
  $form['singular_container']['custom']['background_upload'] = array(
    '#type' => 'file',
    '#title' => t('Upload background image'),
    '#maxlength' => 40,
    '#description' => t("If you don't have direct file access to the server, use this field to upload your background.")
  );

  $form['singular_container']['custom']['background_color'] = array(
    '#title' => t('Background color'),
    '#type' => 'textfield',
    '#size' => '7',
    '#maxlength' => '7',
    '#default_value' => theme_get_setting('background_color'),
    '#suffix' => '<div id="singular-colorpicker"></div>',
    '#attached' => array(
      // Add Farbtastic color picker.
      'library' => array(
        array('system', 'farbtastic'),
      ),
      // Add custom CSS.
      'css' => array(
        $base . '/settings.css' => array(),
      ),
      // Add custom JavaScript.
      'js' => array(
        $base . '/settings.js',
      ),
    ),
  );

  $form['singular_container']['custom']['background_repeat'] = array(
    '#title' => t('Tile'),
    '#type' => 'select',
    '#options' => array(
      'no-repeat' => t('Don\'t tile'),
      'repeat-x' => t('Horizontal'),
      'repeat-y' => t('Vertical'),
      'repeat' => t('Both'),
    ),
    '#default_value' => theme_get_setting('background_repeat'),
  );
  
  $form['#validate'][] = 'singular_theme_settings_validate';
  $form['#submit'][] = 'singular_theme_settings_submit';

  return $form;
}
コード例 #20
0
ファイル: theme-settings.php プロジェクト: ehazell/AZDWR
function comm_form_system_theme_settings_alter(&$form, &$form_state)
{
    //Add the css to fix the color module's goofy form
    drupal_add_css(drupal_get_path('theme', 'comm') . '/css/colors-admin.css');
    //Fix color module rendering of new colors added to .inc file
    comm_theme_settings_add_new_colors();
    /*
     * Sliver show/hide
     */
    $show_sliver = isset($theme_settings['show_sliver']) ? $theme_settings['show_sliver'] : NULL;
    //Add the checkbox to the form
    $form['sliver'] = array('#type' => 'fieldset', '#title' => t('Sliver banner settings'), '#description' => t('If toggled on, the sliver banner will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['sliver']['show_sliver'] = array('#type' => 'checkbox', '#title' => t('Display the sliver banner'), '#default_value' => theme_get_setting('show_sliver'), '#tree' => FALSE, '#description' => t('Check here if you want the theme to display the sliver banner.'));
    /*
       $form['flyout_logo'] = array(
       '#type' => 'fieldset',
       '#title' => t('Flyout Menu Logo'),
       '#description' => t('If toggled on, the sliver banner will be displayed.'),
       '#attributes' => array('class' => array('theme-settings-bottom')),
       );
       $form['flyout_logo']['show_logo'] = array(
       '#type' => 'checkbox',
       '#title' => t('Display the Flyout Logo'),
       '#default_value' => theme_get_setting('show_logo'),
       '#tree' => FALSE,
       '#description' => t('Check here if you want the theme to display the sliver banner.')
       );*/
    /*
     * Background Image
     */
    $background_path = isset($theme_settings['background_path']) ? $theme_settings['background_path'] : NULL;
    // If $background_path is a public:// URI, display the path relative to the files directory. (Stream wrappers are not end-user friendly)
    if (file_uri_scheme($background_path) == 'public') {
        $background_path = file_uri_target($background_path);
    }
    //Add the background image fields to the form
    $form['background_image'] = array('#type' => 'fieldset', '#title' => t('Background image settings'), '#description' => t('If toggled on, the following background will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['background_image']['default_background'] = array('#type' => 'checkbox', '#title' => t('Use the default background'), '#default_value' => theme_get_setting('default_background'), '#tree' => FALSE, '#description' => t('Check here if you want the theme to use the background supplied with it.'));
    $form['background_image']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="default_background"]' => array('checked' => TRUE))));
    $form['background_image']['settings']['background_path'] = array('#type' => 'textfield', '#title' => t('Path to custom background'), '#description' => t('The path to the file you would like to use as your background file instead of the default background.'), '#default_value' => theme_get_setting('background_path'));
    $form['background_image']['settings']['background_file'] = array('#type' => 'file', '#title' => t('Upload background image'), '#maxlength' => 40, '#description' => t("If you don't have direct file access to the server, use this field to upload your background image."), '#element_validate' => array('_comm_theme_settings_validate'));
    /*
       // Flyout Text that displays below the menu
       $form['flyout_nav'] = array(
       '#type' => 'fieldset',
       '#title' => t('Flyout Nav Menu Text'),
       '#description' => t('If toggled on, the following text will be displayed.'),
       '#attributes' => array('class' => array('theme-flyout-nav')),
       );
       $form['flyout_nav']['use_flyout_text'] = array(
       '#type' => 'checkbox',
       '#title' => t('Use the text below in the flyout menu.'),
       '#default_value' => theme_get_setting('use_flyout_text'),
       '#tree' => FALSE,
       '#description' => t('Check here if you want to display the text.')
       );
       $flyout_nav_text = theme_get_setting('flyout_nav_text');
       $form['flyout_nav']['flyout_nav_text'] = array(
       '#type' => 'text_format',
       '#title' => t('Flyout text Area'),
       '#default_value' => $flyout_nav_text['value'],
       '#format' => $flyout_nav_text['format'],
       );*/
    //Toggle display of the branding block in the footer
    /*
       $form['footer_branding'] = array(
       '#type' => 'fieldset',
       '#title' => t('Footer Branding settings'),
       '#description' => t('If toggled on, the branding block will be displayed.'),
       '#attributes' => array('class' => array('theme-settings-bottom')),
       );
       $form['footer_branding']['display_footer_branding'] = array(
       '#type' => 'checkbox',
       '#title' => t('Display the branding block in the footer'),
       '#default_value' => theme_get_setting('display_footer_branding'),
       '#tree' => FALSE,
       '#description' => t('Check here if you want to display the branding  block in the footer.')
       );*/
    //Capture the information for the Contact Us section in the footer
    $form['footer_contact_us'] = array('#type' => 'fieldset', '#title' => t('Flyout "Contact Us" settings'), '#description' => t('If toggled on, the Contact Us block will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['footer_contact_us']['display_footer_contact'] = array('#type' => 'checkbox', '#title' => t('Display the Contact Us block in the flyout region.'), '#default_value' => theme_get_setting('display_footer_contact'), '#tree' => FALSE, '#description' => t('Check here if you want to display the Contact Us block in the flyout region.'));
    $form['footer_contact_us']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="display_footer_contact"]' => array('checked' => FALSE))));
    $form['footer_contact_us']['settings']['footer_contact_us_title'] = array('#type' => 'textfield', '#title' => t('Title'), '#description' => t('Title for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_title'));
    $form['footer_contact_us']['settings']['footer_contact_us_title_link'] = array('#type' => 'textfield', '#title' => t('Title Link'), '#description' => t('Link for the title in the Contact Us block. (Recommend linking to the contact form.)'), '#default_value' => theme_get_setting('footer_contact_us_title_link'));
    $form['footer_contact_us']['settings']['footer_contact_us_comm_title'] = array('#type' => 'textfield', '#title' => t('Agency Title'), '#description' => t('Commercial title for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_comm_title'));
    $form['footer_contact_us']['settings']['footer_contact_us_address_1'] = array('#type' => 'textfield', '#title' => t('Address Line 1'), '#description' => t('Address line 1 for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_address_1'));
    $form['footer_contact_us']['settings']['footer_contact_us_address_2'] = array('#type' => 'textfield', '#title' => t('Address Line 2'), '#description' => t('Address line 2 for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_address_2'));
    $form['footer_contact_us']['settings']['footer_contact_us_phone'] = array('#type' => 'textfield', '#title' => t('Phone Number'), '#description' => t('Phone number for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_phone'));
    $form['footer_contact_us']['settings']['footer_contact_us_fax'] = array('#type' => 'textfield', '#title' => t('Fax Number'), '#description' => t('Fax number for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_fax'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_link'] = array('#type' => 'textfield', '#title' => t('Map Link'), '#description' => t('Link for the map in the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_map_link'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_path'] = array('#type' => 'textfield', '#title' => t('Path to map image'), '#description' => t('The path to the file you would like to use as your map image. (150px x 150px)'), '#default_value' => theme_get_setting('footer_contact_us_map_path'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_image'] = array('#type' => 'file', '#title' => t('Upload map image'), '#maxlength' => 40, '#description' => t("Use this field to upload your map image. (150px x 150px.  Will be resized if necessary.)"), '#element_validate' => array('_comm_theme_settings_map'));
    //End Contact Us
    //Sticky Nav Block
    $sticky_nav_path = isset($theme_settings['sticky_nav_path']) ? $theme_settings['sticky_nav_path'] : NULL;
    // If $sticky_nav_path is a public:// URI, display the path relative to the files directory. (Stream wrappers are not end-user friendly)
    if (file_uri_scheme($sticky_nav_path) == 'public') {
        $sticky_nav_path = file_uri_target($sticky_nav_path);
    }
    //Add the sticky_nav image fields to the form
    $form['sticky_nav_image'] = array('#type' => 'fieldset', '#title' => t('Sticky Nav Menu Logo settings'), '#description' => t('The Sticky Nav is the top bar that contains links and menu icon.'), '#attributes' => array('class' => array('theme-sticky-nav')));
    $form['sticky_nav_image']['use_sticky_nav'] = array('#type' => 'checkbox', '#title' => t('Use a logo for the sticky nav.'), '#default_value' => theme_get_setting('use_sticky_nav'), '#tree' => FALSE, '#description' => t('Check here if you want to display this image in the sticky nav.'));
    $form['sticky_nav_image']['settings']['sticky_nav_path'] = array('#type' => 'textfield', '#title' => t('Path to custom sticky nav icon'), '#description' => t('The path to the file you would like to use as your sticky nav logo file.'), '#default_value' => theme_get_setting('sticky_nav_path'));
    $form['sticky_nav_image']['settings']['sticky_nav_file'] = array('#type' => 'file', '#title' => t('Upload background image'), '#maxlength' => 40, '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."), '#element_validate' => array('_comm_theme_settings_flyout'));
    $stickyMobile = theme_get_setting('sticky_nav_mobile');
    if ($stickyMobile != null) {
        $form['sticky_nav_image']['sticky_nav_mobile'] = array('#type' => 'radios', '#title' => t('When to display the sticky nav.'), '#default_value' => theme_get_setting('sticky_nav_mobile'), '#options' => array(1 => 'Display the Sticky Nav only in mobile display', 0 => 'Display the Sticky Nav in desktop and mobile displays'));
    } else {
        $form['sticky_nav_image']['sticky_nav_mobile'] = array('#type' => 'radios', '#title' => t('When to display the sticky nav.'), '#default_value' => 1, '#options' => array(1 => 'Display the Sticky Nav only in mobile display', 0 => 'Display the Sticky Nav in desktop and mobile displays'));
    }
    //End Sticky Nav Block
    return $form;
}
コード例 #21
0
 /**
  * Loads a RestWS Schema object.
  *
  * @param int $id
  *   The original entity ID.
  *
  * @return stdClass
  *   An object matching the requested RestWS Schema object structure.
  */
 protected function objectLoad($id)
 {
     $object = new stdClass();
     // Get original entity.
     $original_wrapper = $this->originalWrapper($id);
     // If the wrapped entity is not of the correct bundle, bail now.
     if ($original_wrapper->getBundle() !== $this->bundleName) {
         return $object;
     }
     $original_properties = $original_wrapper->getPropertyInfo();
     // Add to our object according to our defined API property info.
     if ($map = $this->apiMap[$this->resource()]) {
         foreach (array_keys($this->propertyInfo) as $property) {
             if (array_key_exists($map[$property], $original_properties)) {
                 $value = $original_wrapper->{$map[$property]}->value(array('sanitize' => TRUE));
                 // Do some specific things for fields.
                 if ($field = field_info_field($map[$property])) {
                     // We assume the first column is the primary value column. This is
                     // how Views gets the $real_field.
                     // @see field_views_field_default_views_data()
                     $column = key($field['columns']);
                 }
                 // For now make a quick check for references, and build an array of
                 // reference objects.
                 // @todo Abstract this by creating our own format handler, using
                 //   hook_restws_format_info_alter(), which extends RestWSFormatJSON,
                 //   and overrides RestWSBaseFormat::getResourceReferenceValue.
                 if ($field && $field['type'] == 'entityreference' && ($type = $field['settings']['target_type'])) {
                     // Return an array of values, regardless of field cardinality.
                     $value = !is_array($value) ? array($value) : $value;
                     $values = array();
                     foreach ($value as $item) {
                         list($id, , $target_bundle) = entity_extract_ids($type, $item);
                         $target_resource = NULL;
                         // Get target resource from map.
                         foreach ($this->apiMap as $r => $i) {
                             if ($i['entity'] == $type && $i['bundle'] == $target_bundle) {
                                 $target_resource = $r;
                                 break;
                             }
                         }
                         $values[] = (object) array('uri' => restws_resource_uri($target_resource, $id), 'resource' => $target_resource, 'id' => $id);
                     }
                     $value = $values;
                 } elseif ($field && $field['type'] == 'image') {
                     $values = array();
                     foreach ($value as $key => $item) {
                         $values[$key] = array('alt' => $item['alt'], 'title' => $item['title'], 'mime' => $item['filemime']);
                         $values[$key]['sizes']['original'] = array('uri' => file_uri_target($item['uri']), 'height' => $item['height'], 'width' => $item['width']);
                         foreach (image_styles() as $style_name => $style) {
                             $values[$key]['sizes'][$style_name] = array('uri' => image_style_url($style_name, $item['uri']), 'height' => $style['effects'][0]['data']['height'], 'width' => $style['effects'][0]['data']['width']);
                         }
                     }
                     $value = $values;
                 } elseif ($field && is_array($value)) {
                     try {
                         $value = $original_wrapper->{$map[$property]}->{$column}->value(array('decode' => TRUE));
                     } catch (EntityMetadataWrapperException $e) {
                     }
                 }
                 $object->{$property} = $value;
             }
         }
     }
     return $object;
 }
コード例 #22
0
ファイル: ThemeTest.php プロジェクト: frankcr/sftw8
 /**
  * Test the theme settings form.
  */
 function testThemeSettings()
 {
     // Ensure invalid theme settings form URLs return a proper 404.
     $this->drupalGet('admin/appearance/settings/bartik');
     $this->assertResponse(404, 'The theme settings form URL for a uninstalled theme could not be found.');
     $this->drupalGet('admin/appearance/settings/' . $this->randomMachineName());
     $this->assertResponse(404, 'The theme settings form URL for a non-existent theme could not be found.');
     $this->assertTrue(\Drupal::service('theme_installer')->install(['stable']));
     $this->drupalGet('admin/appearance/settings/stable');
     $this->assertResponse(404, 'The theme settings form URL for a hidden theme is unavailable.');
     // Specify a filesystem path to be used for the logo.
     $file = current($this->drupalGetTestFiles('image'));
     $file_relative = strtr($file->uri, array('public:/' => PublicStream::basePath()));
     $default_theme_path = 'core/themes/classy';
     $supported_paths = array($file->uri => array('form' => file_uri_target($file->uri), 'src' => file_url_transform_relative(file_create_url($file->uri))), file_uri_target($file->uri) => array('form' => file_uri_target($file->uri), 'src' => file_url_transform_relative(file_create_url($file->uri))), $file_relative => array('form' => $file_relative, 'src' => file_url_transform_relative(file_create_url($file->uri))), 'core/misc/druplicon.png' => array('form' => 'core/misc/druplicon.png', 'src' => base_path() . 'core/misc/druplicon.png'), $default_theme_path . '/logo.svg' => array('form' => $default_theme_path . '/logo.svg', 'src' => base_path() . $default_theme_path . '/logo.svg'));
     foreach ($supported_paths as $input => $expected) {
         $edit = array('default_logo' => FALSE, 'logo_path' => $input);
         $this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration'));
         $this->assertNoText('The custom logo path is invalid.');
         $this->assertFieldByName('logo_path', $expected['form']);
         // Verify logo path examples.
         $elements = $this->xpath('//div[contains(@class, :item)]/div[@class=:description]/code', array(':item' => 'js-form-item-logo-path', ':description' => 'description'));
         // Expected default values (if all else fails).
         $implicit_public_file = 'logo.svg';
         $explicit_file = 'public://logo.svg';
         $local_file = $default_theme_path . '/logo.svg';
         // Adjust for fully qualified stream wrapper URI in public filesystem.
         if (file_uri_scheme($input) == 'public') {
             $implicit_public_file = file_uri_target($input);
             $explicit_file = $input;
             $local_file = strtr($input, array('public:/' => PublicStream::basePath()));
         } elseif (file_uri_scheme($input) !== FALSE) {
             $explicit_file = $input;
         } elseif ($input == file_uri_target($file->uri)) {
             $implicit_public_file = $input;
             $explicit_file = 'public://' . $input;
             $local_file = PublicStream::basePath() . '/' . $input;
         }
         $this->assertEqual((string) $elements[0], $implicit_public_file);
         $this->assertEqual((string) $elements[1], $explicit_file);
         $this->assertEqual((string) $elements[2], $local_file);
         // Verify the actual 'src' attribute of the logo being output in a site
         // branding block.
         $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
         $this->drupalGet('');
         $elements = $this->xpath('//header//a[@rel=:rel]/img', array(':rel' => 'home'));
         $this->assertEqual((string) $elements[0]['src'], $expected['src']);
     }
     $unsupported_paths = array('public://whatever.png', 'private://whatever.png', 'temporary://whatever.png', 'public:/whatever.png', '://whatever.png', ':whatever.png', 'public://', 'whatever.png', PublicStream::basePath() . '/whatever.png', '/' . PublicStream::basePath() . '/whatever.png', 'core/misc/whatever.png', '/core/misc/whatever.png', drupal_realpath($file->uri));
     $this->drupalGet('admin/appearance/settings');
     foreach ($unsupported_paths as $path) {
         $edit = array('default_logo' => FALSE, 'logo_path' => $path);
         $this->drupalPostForm(NULL, $edit, t('Save configuration'));
         $this->assertText('The custom logo path is invalid.');
     }
     // Upload a file to use for the logo.
     $edit = array('default_logo' => FALSE, 'logo_path' => '', 'files[logo_upload]' => drupal_realpath($file->uri));
     $this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration'));
     $fields = $this->xpath($this->constructFieldXpath('name', 'logo_path'));
     $uploaded_filename = 'public://' . $fields[0]['value'];
     $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
     $this->drupalGet('');
     $elements = $this->xpath('//header//a[@rel=:rel]/img', array(':rel' => 'home'));
     $this->assertEqual($elements[0]['src'], file_url_transform_relative(file_create_url($uploaded_filename)));
     $this->container->get('theme_handler')->install(array('bartik'));
     // Ensure only valid themes are listed in the local tasks.
     $this->drupalPlaceBlock('local_tasks_block', ['region' => 'header']);
     $this->drupalGet('admin/appearance/settings');
     $theme_handler = \Drupal::service('theme_handler');
     $this->assertLink($theme_handler->getName('classy'));
     $this->assertLink($theme_handler->getName('bartik'));
     $this->assertNoLink($theme_handler->getName('stable'));
     // If a hidden theme is an admin theme it should be viewable.
     \Drupal::configFactory()->getEditable('system.theme')->set('admin', 'stable')->save();
     \Drupal::service('router.builder')->rebuildIfNeeded();
     $this->drupalPlaceBlock('local_tasks_block', ['region' => 'header', 'theme' => 'stable']);
     $this->drupalGet('admin/appearance/settings');
     $this->assertLink($theme_handler->getName('stable'));
     $this->drupalGet('admin/appearance/settings/stable');
     $this->assertResponse(200, 'The theme settings form URL for a hidden theme that is the admin theme is available.');
 }
コード例 #23
0
ファイル: theme-settings.php プロジェクト: 609/FA
function blocks_form_system_theme_settings_alter(&$form, &$form_state)
{
    global $slide_number;
    // Default path for image
    $bg_path = theme_get_setting('bg_path');
    if (file_uri_scheme($bg_path) == 'public') {
        $bg_path = file_uri_target($bg_path);
    }
    // Default path for back-ground image
    $background_path = theme_get_setting('background_path');
    if (file_uri_scheme($background_path) == 'public') {
        $background_path = file_uri_target($background_path);
    }
    $count = 1;
    while ($count <= $slide_number) {
        ${'slide_path_' . $count} = theme_get_setting('slide_path_' . $count . '');
        if (file_uri_scheme(${'slide_path_' . $count}) == 'public') {
            ${'slide_path_' . $count} = file_uri_target(${'slide_path_' . $count});
        }
        $count++;
    }
    // Container
    $form['options'] = array('#type' => 'vertical_tabs', '#default_tab' => 'defaults', '#weight' => '-10', '#attached' => array('css' => array(drupal_get_path('theme', 'blocks') . '/css/theme-options.css')));
    // General
    $form['options']['general'] = array('#type' => 'fieldset', '#title' => 'General');
    // Breadcrumbs
    $form['options']['general']['breadcrumbs'] = array('#type' => 'checkbox', '#title' => 'Breadcrumbs', '#default_value' => theme_get_setting('breadcrumbs'));
    // SEO
    $form['options']['general']['seo'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">SEO</h3>');
    // SEO Title
    $form['options']['general']['seo']['seo_title'] = array('#type' => 'textfield', '#title' => 'Title', '#default_value' => theme_get_setting('seo_title'));
    // SEO Description
    $form['options']['general']['seo']['seo_description'] = array('#type' => 'textarea', '#title' => 'Description', '#default_value' => theme_get_setting('seo_description'));
    // SEO Keywords
    $form['options']['general']['seo']['seo_keywords'] = array('#type' => 'textarea', '#title' => 'Keywords', '#default_value' => theme_get_setting('seo_keywords'));
    // Header Options
    $form['options']['header'] = array('#type' => 'fieldset', '#title' => t('Header'));
    // Logo
    $form['options']['header']['branding'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Branding</h3>');
    // Logo Toggle
    $form['options']['header']['branding']['branding_type'] = array('#type' => 'select', '#title' => 'Branding Type', '#default_value' => theme_get_setting('branding_type'), '#options' => array('logo' => 'Logo', 'text' => 'Text'));
    $form['options']['header']['branding']['bg_path'] = array('#type' => 'textfield', '#title' => 'Path to logo', '#default_value' => $bg_path, '#disabled' => TRUE, '#states' => array('visible' => array('#edit-branding-type' => array('value' => 'logo'))));
    $form['options']['header']['branding']['bg_upload'] = array('#type' => 'file', '#title' => 'Upload logo', '#description' => 'Upload a new logo image.', '#states' => array('visible' => array('#edit-branding-type' => array('value' => 'logo'))));
    //for back-ground image
    $form['options']['header']['branding']['background_path'] = array('#type' => 'textfield', '#title' => 'Path to Background image', '#default_value' => $background_path, '#disabled' => TRUE, '#states' => array('visible' => array('#edit-branding-type' => array('value' => 'background'))));
    $form['options']['header']['branding']['background_upload'] = array('#type' => 'file', '#title' => 'Upload Back-ground image', '#description' => 'Upload a Back-ground image.', '#states' => array('visible' => array('#edit-branding-type' => array('value' => 'background'))));
    // Social Icons
    $form['options']['header']['social'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Social Icons</h3>');
    // Twitter Icon
    $form['options']['header']['social']['twitter_icon'] = array('#type' => 'checkbox', '#title' => 'Twitter Icon', '#default_value' => theme_get_setting('twitter_icon'));
    // Twitter Icon URL
    $form['options']['header']['social']['twitter_url'] = array('#type' => 'textfield', '#title' => 'Twitter URL', '#default_value' => theme_get_setting('twitter_url'), '#size' => 10, '#maxlenght' => 10, '#states' => array('invisible' => array('input[name="twitter_icon"]' => array('checked' => FALSE))));
    // Facebook Icon
    $form['options']['header']['social']['facebook_icon'] = array('#type' => 'checkbox', '#title' => 'Facebook Icon', '#default_value' => theme_get_setting('facebook_icon'));
    // Facebook Icon URL
    $form['options']['header']['social']['facebook_url'] = array('#type' => 'textfield', '#title' => 'Facebook URL', '#default_value' => theme_get_setting('facebook_url'), '#states' => array('invisible' => array('input[name="facebook_icon"]' => array('checked' => FALSE))));
    // Flickr Icon
    $form['options']['header']['social']['flickr_icon'] = array('#type' => 'checkbox', '#title' => 'Flickr Icon', '#default_value' => theme_get_setting('flickr_icon'));
    // Flickr Icon URL
    $form['options']['header']['social']['flickr_url'] = array('#type' => 'textfield', '#title' => 'Flickr URL', '#default_value' => theme_get_setting('flickr_url'), '#states' => array('invisible' => array('input[name="flickr_icon"]' => array('checked' => FALSE))));
    // Google Plus Icon
    $form['options']['header']['social']['google_plus_icon'] = array('#type' => 'checkbox', '#title' => 'Google+ Icon', '#default_value' => theme_get_setting('google_plus_icon'));
    // Google Plus URL
    $form['options']['header']['social']['google_plus_url'] = array('#type' => 'textfield', '#title' => 'Google+ URL', '#default_value' => theme_get_setting('google_plus_url'), '#states' => array('invisible' => array('input[name="google_plus_icon"]' => array('checked' => FALSE))));
    // Pinterest Icon
    $form['options']['header']['social']['pinterest_icon'] = array('#type' => 'checkbox', '#title' => 'Pinterest Icon', '#default_value' => theme_get_setting('pinterest_icon'));
    // Pinterest URL
    $form['options']['header']['social']['pinterest_url'] = array('#type' => 'textfield', '#title' => 'Pinterest URL', '#default_value' => theme_get_setting('pinterest_url'), '#states' => array('invisible' => array('input[name="pinterest_icon"]' => array('checked' => FALSE))));
    // LinkedIn Icon
    $form['options']['header']['social']['linkedin_icon'] = array('#type' => 'checkbox', '#title' => 'LinkedIn Icon', '#default_value' => theme_get_setting('linkedin_icon'));
    // linkedin URL
    $form['options']['header']['social']['linkedin_url'] = array('#type' => 'textfield', '#title' => 'LinkedIn URL', '#default_value' => theme_get_setting('linkedin_url'), '#states' => array('invisible' => array('input[name="linkedin_icon"]' => array('checked' => FALSE))));
    // Youtube Icon
    $form['options']['header']['social']['youtube_icon'] = array('#type' => 'checkbox', '#title' => 'Youtube Icon', '#default_value' => theme_get_setting('youtube_icon'));
    // Youtube URL
    $form['options']['header']['social']['youtube_url'] = array('#type' => 'textfield', '#title' => 'Youtube URL', '#default_value' => theme_get_setting('youtube_url'), '#states' => array('invisible' => array('input[name="youtube_icon"]' => array('checked' => FALSE))));
    // Vimeo Icon
    $form['options']['header']['social']['vimeo_icon'] = array('#type' => 'checkbox', '#title' => 'Vimeo Icon', '#default_value' => theme_get_setting('vimeo_icon'));
    // Youtube URL
    $form['options']['header']['social']['vimeo_url'] = array('#type' => 'textfield', '#title' => 'Vimeo URL', '#default_value' => theme_get_setting('vimeo_url'), '#states' => array('invisible' => array('input[name="vimeo_icon"]' => array('checked' => FALSE))));
    // RSS Icon
    $form['options']['header']['social']['rss_icon'] = array('#type' => 'checkbox', '#title' => 'RSS Icon', '#default_value' => theme_get_setting('rss_icon'));
    // Twitter URL
    $form['options']['header']['social']['rss_url'] = array('#type' => 'textfield', '#title' => 'RSS URL', '#default_value' => theme_get_setting('rss_url'), '#states' => array('invisible' => array('input[name="rss_icon"]' => array('checked' => FALSE))));
    // Front Page
    $form['options']['front_page'] = array('#type' => 'fieldset', '#title' => 'Front Page');
    // Slider
    $form['options']['front_page']['slider'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Image Slider</h3>');
    // Enable Slider
    $form['options']['front_page']['slider']['enable_slider'] = array('#type' => 'checkbox', '#title' => 'Enable Image Slider', '#default_value' => theme_get_setting('enable_slider'));
    $form['options']['front_page']['slider']['slide_1'] = array('#type' => 'fieldset', '#title' => '<h3>Slide 1</h3>', '#states' => array('invisible' => array('input[name="enable_slider"]' => array('checked' => FALSE))));
    $form['options']['front_page']['slider']['slide_1']['slide1_img1'] = array('#type' => 'textfield', '#title' => 'Image path to slide 1, image 1', '#default_value' => theme_get_setting('slide1_img1'));
    $form['options']['front_page']['slider']['slide_1']['slide1_img2'] = array('#type' => 'textfield', '#title' => 'Image path to slide 1, image 2', '#default_value' => theme_get_setting('slide1_img2'));
    $form['options']['front_page']['slider']['slide_1']['slide1_img3'] = array('#type' => 'textfield', '#title' => 'Image path to slide 1, image 3', '#default_value' => theme_get_setting('slide1_img3'));
    $form['options']['front_page']['slider']['slide_1']['slide1_txt1'] = array('#type' => 'textfield', '#title' => 'Text for slide 1, caption 1', '#default_value' => theme_get_setting('slide1_txt1'));
    $form['options']['front_page']['slider']['slide_1']['slide1_txt2'] = array('#type' => 'textfield', '#title' => 'Text for slide 1, caption 2', '#default_value' => theme_get_setting('slide1_txt2'));
    $form['options']['front_page']['slider']['slide_2'] = array('#type' => 'fieldset', '#title' => '<h3>Slide 2</h3>', '#states' => array('invisible' => array('input[name="enable_slider"]' => array('checked' => FALSE))));
    $form['options']['front_page']['slider']['slide_2']['slide2_txt1'] = array('#type' => 'textfield', '#title' => 'Text for slide 2, caption 1', '#default_value' => theme_get_setting('slide2_txt1'));
    $form['options']['front_page']['slider']['slide_2']['slide2_txt2'] = array('#type' => 'textfield', '#title' => 'Text for slide 2, caption 2', '#default_value' => theme_get_setting('slide2_txt2'));
    $form['options']['front_page']['slider']['slide_2']['slide2_img1'] = array('#type' => 'textfield', '#title' => 'Image path to slide 2, image 1', '#default_value' => theme_get_setting('slide2_img1'));
    $form['options']['front_page']['slider']['slide_2']['slide2_img2'] = array('#type' => 'textfield', '#title' => 'Image path to slide 2, image 2', '#default_value' => theme_get_setting('slide2_img2'));
    $form['options']['front_page']['slider']['slide_2']['slide2_img3'] = array('#type' => 'textfield', '#title' => 'Image path to slide 2, image 3', '#default_value' => theme_get_setting('slide2_img3'));
    $form['options']['front_page']['slider']['slide_3'] = array('#type' => 'fieldset', '#title' => '<h3>Slide 3</h3>', '#states' => array('invisible' => array('input[name="enable_slider"]' => array('checked' => FALSE))));
    $form['options']['front_page']['slider']['slide_3']['slide3_img1'] = array('#type' => 'textfield', '#title' => 'Image path to slide 3, image 1', '#default_value' => theme_get_setting('slide3_img1'));
    $form['options']['front_page']['slider']['slide_3']['slide3_txt1'] = array('#type' => 'textfield', '#title' => 'Text for slide 3, caption 1', '#default_value' => theme_get_setting('slide3_txt1'));
    $form['options']['front_page']['slider']['slide_3']['slide3_txt2'] = array('#type' => 'textfield', '#title' => 'Text for slide 3, caption 2', '#default_value' => theme_get_setting('slide3_txt2'));
    $form['options']['front_page']['slider']['slide_3']['slide3_txt3'] = array('#type' => 'textfield', '#title' => 'Text for slide 3, caption 3', '#default_value' => theme_get_setting('slide3_txt3'));
    // Services
    $form['options']['front_page']['services'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Services</h3>');
    // Enable Services
    $form['options']['front_page']['services']['enable_services'] = array('#type' => 'checkbox', '#title' => 'Enable Services Section', '#default_value' => theme_get_setting('enable_services'));
    //Services Title
    $form['options']['front_page']['services']['services_title'] = array('#type' => 'textfield', '#title' => 'Services Title', '#default_value' => theme_get_setting('services_title'), '#states' => array('invisible' => array('input[name="enable_services"]' => array('checked' => FALSE))));
    // Highlight
    $form['options']['front_page']['highlight'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Highlight</h3>');
    // Enable highlight
    $form['options']['front_page']['highlight']['enable_highlight'] = array('#type' => 'checkbox', '#title' => 'Enable Highlight', '#default_value' => theme_get_setting('enable_highlight'));
    // highlight Text
    $form['options']['front_page']['highlight']['highlight_text'] = array('#type' => 'textarea', '#title' => 'Highlight Text', '#default_value' => theme_get_setting('highlight_text'), '#states' => array('invisible' => array('input[name="enable_highlight"]' => array('checked' => FALSE))));
    // Recent Posts
    $form['options']['front_page']['recent_posts'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Recent Posts</h3>');
    // Enable Services
    $form['options']['front_page']['recent_posts']['enable_recent_posts'] = array('#type' => 'checkbox', '#title' => 'Enable Recent Posts Section', '#default_value' => theme_get_setting('enable_recent_posts'));
    //Services Title
    $form['options']['front_page']['recent_posts']['recent_posts_title'] = array('#type' => 'textfield', '#title' => 'Recent Posts Title', '#default_value' => theme_get_setting('recent_posts_title'), '#states' => array('invisible' => array('input[name="enable_recent_posts"]' => array('checked' => FALSE))));
    // Recent Projects
    $form['options']['front_page']['recent_projects'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Recent Projects</h3>');
    // Enable Services
    $form['options']['front_page']['recent_projects']['enable_recent_projects'] = array('#type' => 'checkbox', '#title' => 'Enable Recent Projects Section', '#default_value' => theme_get_setting('enable_recent_projects'));
    //Services Title
    $form['options']['front_page']['recent_projects']['recent_projects_title'] = array('#type' => 'textfield', '#title' => 'Recent Projects Title', '#default_value' => theme_get_setting('recent_projects_title'), '#states' => array('invisible' => array('input[name="enable_recent_projects"]' => array('checked' => FALSE))));
    // Layout
    $form['options']['layout'] = array('#type' => 'fieldset', '#title' => 'Layout');
    // Enable boxed layout
    $form['options']['layout']['enable_boxed_layout'] = array('#type' => 'checkbox', '#title' => 'Enable boxed layout', '#default_value' => theme_get_setting('enable_boxed_layout'));
    // Page Layout
    $form['options']['layout']['page_layout'] = array('#type' => 'radios', '#title' => 'Select a page layout:', '#default_value' => theme_get_setting('page_layout'), '#options' => array('sidebar_right' => 'Sidebar Right', 'full_width' => 'Full Width'));
    // Blog Layout
    $form['options']['layout']['blog_layout'] = array('#type' => 'radios', '#title' => 'Select a blog layout:', '#default_value' => theme_get_setting('blog_layout'), '#options' => array('sidebar_right' => 'Sidebar Right', 'full_width' => 'Full Width'));
    // Portfolio Columns
    $form['options']['layout']['portfolio_columns'] = array('#type' => 'select', '#title' => 'Portfolio Columns', '#default_value' => theme_get_setting('portfolio_columns'), '#options' => array('six' => 'Two', 'four' => 'Three', 'three' => 'Four (default)'));
    // Design
    $form['options']['design'] = array('#type' => 'fieldset', '#title' => 'Design');
    // Colors
    $form['options']['design']['colors'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Color Scheme</h3>');
    // Color Scheme
    $form['options']['design']['colors']['color_scheme'] = array('#type' => 'select', '#title' => 'Color Scheme', '#default_value' => theme_get_setting('color_scheme'), '#options' => array('black' => 'Black', 'blue' => 'Blue (default)', 'teal' => 'Teal', 'green' => 'Green', 'yellow' => 'Yellow', 'purple' => 'Purple', 'orange' => 'Orange', 'red' => 'Red'));
    // Background
    $form['options']['design']['background'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Background</h3>');
    // Background Color
    $form['options']['design']['background']['body_background'] = array('#type' => 'textfield', '#title' => 'Body background color', '#default_value' => theme_get_setting('body_background'));
    // Enable background pattern
    $form['options']['design']['background']['enable_background_pattern'] = array('#type' => 'checkbox', '#title' => 'Enable background pattern', '#default_value' => theme_get_setting('enable_background_pattern'));
    // Background
    $form['options']['design']['background']['background_select'] = array('#type' => 'radios', '#title' => 'Select a background pattern:', '#default_value' => theme_get_setting('background_select'), '#options' => array('gplaypattern' => 'item', 'grey' => 'item', 'retina_wood' => 'item', 'noisy_grid' => 'item', 'cartographer' => 'item', 'bedge' => 'item', 'illusion' => 'item', 'nistri' => 'item'), '#states' => array('invisible' => array('input[name="enable_background_pattern"]' => array('checked' => FALSE))));
    // Background
    $form['options']['design']['page_heading'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Page Heading</h3>');
    // Background Color
    $form['options']['design']['page_heading']['heading_background'] = array('#type' => 'textfield', '#title' => 'Page/slider heading background color', '#default_value' => theme_get_setting('heading_background'));
    // Enable background pattern
    $form['options']['design']['page_heading']['enable_heading_pattern'] = array('#type' => 'checkbox', '#title' => 'Enable heading pattern', '#default_value' => theme_get_setting('enable_heading_pattern'));
    // Background
    $form['options']['design']['page_heading']['heading_background_select'] = array('#type' => 'radios', '#title' => 'Select a heading background pattern:', '#default_value' => theme_get_setting('heading_background_select'), '#options' => array('shattered' => 'item', 'tile' => 'item', 'checkered' => 'item', 'bullseyes' => 'item', 'gplaypattern' => 'item', 'cartographer' => 'item', 'linen' => 'item', 'dark_wood' => 'item'), '#states' => array('invisible' => array('input[name="enable_heading_pattern"]' => array('checked' => FALSE))));
    // CSS
    $form['options']['design']['css'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">CSS</h3>');
    // User CSS
    $form['options']['design']['css']['user_css'] = array('#type' => 'textarea', '#title' => 'Add your own CSS', '#default_value' => theme_get_setting('user_css'));
    // Typography
    $form['options']['typography'] = array('#type' => 'fieldset', '#title' => 'Typography');
    // Font
    $form['options']['typography']['font'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Body Font</h3>');
    // Font Family
    $form['options']['typography']['font']['font_family'] = array('#type' => 'select', '#title' => 'Select a font family', '#default_value' => theme_get_setting('font_family'), '#options' => array('Open Sans Condensed, serif' => '"Open Sans Condensed", serif (default)', 'Open Sans, serif' => '"Open Sans", serif', 'Arial, Helvetica, sans-serif' => 'Arial, Helvetica, sans-serif', 'Georgia, serif' => 'Georgia, serif', '"Helvetica Neue", Helvetica, Arial, sans-serif' => '"Helvetica Neue", Helvetica, Arial, sans-serif', '"Times New Roman", Times, serif' => '"Times New Roman", Times, serif', 'Verdana, Arial, Helvetica, sans-serif' => 'Verdana, Arial, Helvetica, sans-serif'));
    //Headings
    $form['options']['typography']['headings'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Headings</h3>');
    // Font Family
    $form['options']['typography']['headings']['headings_font_family'] = array('#type' => 'select', '#title' => 'Select a font family', '#default_value' => theme_get_setting('headings_font_family'), '#options' => array('Open Sans Condensed, serif' => '"Open Sans Condensed", serif (default)', 'Open Sans, serif' => '"Open Sans", serif', 'Arial, Helvetica, sans-serif' => 'Arial, Helvetica, sans-serif', 'Georgia, serif' => 'Georgia, serif', '"Helvetica Neue", Helvetica, Arial, sans-serif' => '"Helvetica Neue", Helvetica, Arial, sans-serif', '"Times New Roman", Times, serif' => '"Times New Roman", Times, serif', 'Verdana, Arial, Helvetica, sans-serif' => 'Verdana, Arial, Helvetica, sans-serif'));
    //H1
    $form['options']['typography']['headings']['h1'] = array('#type' => 'textfield', '#title' => 'h1 Size', '#default_value' => theme_get_setting('h1'));
    //H2
    $form['options']['typography']['headings']['h2'] = array('#type' => 'textfield', '#title' => 'h2 Size', '#default_value' => theme_get_setting('h2'));
    //H3
    $form['options']['typography']['headings']['h3'] = array('#type' => 'textfield', '#title' => 'h3 Size', '#default_value' => theme_get_setting('h3'));
    //H4
    $form['options']['typography']['headings']['h4'] = array('#type' => 'textfield', '#title' => 'h4 Size', '#default_value' => theme_get_setting('h4'));
    //H5
    $form['options']['typography']['headings']['h5'] = array('#type' => 'textfield', '#title' => 'h5 Size', '#default_value' => theme_get_setting('h5'));
    //H6
    $form['options']['typography']['headings']['h6'] = array('#type' => 'textfield', '#title' => 'h6 Size', '#default_value' => theme_get_setting('h6'));
    // Footer
    $form['options']['footer'] = array('#type' => 'fieldset', '#title' => 'Footer');
    // Enable Primary Footer
    $form['options']['footer']['enable_primary_footer'] = array('#type' => 'checkbox', '#title' => 'Enable Primary Footer', '#default_value' => theme_get_setting('enable_primary_footer'));
    // Secondary Footer
    $form['options']['footer']['secondary_footer'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Secondary Footer</h3>');
    // Enable Secondary Footer
    $form['options']['footer']['secondary_footer']['enable_secondary_footer'] = array('#type' => 'checkbox', '#title' => 'Enable Secondary Footer', '#default_value' => theme_get_setting('enable_secondary_footer'));
    // Secondary Footer Left
    $form['options']['footer']['secondary_footer']['secondary_footer_text'] = array('#type' => 'textfield', '#title' => 'Secondary Footer Text', '#default_value' => theme_get_setting('secondary_footer_text'), '#states' => array('invisible' => array('input[name="enable_secondary_footer"]' => array('checked' => FALSE))));
    // Submit Button
    $form['#submit'][] = 'blocks_settings_submit';
    $form['#submit'][] = 'blocks_background_settings_submit';
}
コード例 #24
0
 /**
  * Locate all images in a piece of text that need replacing.
  *
  *   An array of settings that will be used to identify which images need
  *   updating. Includes the following:
  *
  *   - image_locations: An array of acceptable image locations.
  *     of the following values: "remote". Remote image will be downloaded and
  *     saved locally. This procedure is intensive as the images need to
  *     be retrieved to have their dimensions checked.
  *
  * @param string $text
  *   The text to be updated with the new img src tags.
  *
  * @return array $images
  *   An list of images.
  */
 private function getImages($text)
 {
     $dom = Html::load($text);
     $xpath = new \DOMXPath($dom);
     /** @var \DOMNode $node */
     foreach ($xpath->query('//img') as $node) {
         $file = $this->entityRepository->loadEntityByUuid('file', $node->getAttribute('data-entity-uuid'));
         // If the image hasn't an uuid then don't try to resize it.
         if (is_null($file)) {
             continue;
         }
         $image = $this->imageFactory->get($node->getAttribute('src'));
         // Checking if the image needs to be resized.
         if ($image->getWidth() == $node->getAttribute('width') && $image->getHeight() == $node->getAttribute('height')) {
             continue;
         }
         $target = file_uri_target($file->getFileUri());
         $dirname = dirname($target) != '.' ? dirname($target) . '/' : '';
         $info = pathinfo($file->getFileUri());
         $resize_file_path = 'public://resize/' . $dirname . $info['filename'] . '-' . $node->getAttribute('width') . 'x' . $node->getAttribute('height') . '.' . $info['extension'];
         // Checking if the image was already resized:
         if (file_exists($resize_file_path)) {
             $node->setAttribute('src', file_url_transform_relative(file_create_url($resize_file_path)));
             continue;
         }
         // Delete this when https://www.drupal.org/node/2211657#comment-11510213
         // be fixed.
         $dirname = $this->fileSystem->dirname($resize_file_path);
         if (!file_exists($dirname)) {
             file_prepare_directory($dirname, FILE_CREATE_DIRECTORY);
         }
         // Checks if the resize filter exists if is not then create it.
         $copy = file_unmanaged_copy($file->getFileUri(), $resize_file_path, FILE_EXISTS_REPLACE);
         $copy_image = $this->imageFactory->get($copy);
         $copy_image->resize($node->getAttribute('width'), $node->getAttribute('height'));
         $copy_image->save();
         $node->setAttribute('src', file_url_transform_relative(file_create_url($copy)));
     }
     return Html::serialize($dom);
 }
コード例 #25
0
ファイル: ImageStyle.php プロジェクト: anatalsceo/en-classe
 /**
  * {@inheritdoc}
  */
 public function buildUrl($path, $clean_urls = NULL)
 {
     $uri = $this->buildUri($path);
     // The token query is added even if the
     // 'image.settings:allow_insecure_derivatives' configuration is TRUE, so
     // that the emitted links remain valid if it is changed back to the default
     // FALSE. However, sites which need to prevent the token query from being
     // emitted at all can additionally set the
     // 'image.settings:suppress_itok_output' configuration to TRUE to achieve
     // that (if both are set, the security token will neither be emitted in the
     // image derivative URL nor checked for in
     // \Drupal\image\ImageStyleInterface::deliver()).
     $token_query = array();
     if (!\Drupal::config('image.settings')->get('suppress_itok_output')) {
         // The passed $path variable can be either a relative path or a full URI.
         $original_uri = file_uri_scheme($path) ? file_stream_wrapper_uri_normalize($path) : file_build_uri($path);
         $token_query = array(IMAGE_DERIVATIVE_TOKEN => $this->getPathToken($original_uri));
     }
     if ($clean_urls === NULL) {
         // Assume clean URLs unless the request tells us otherwise.
         $clean_urls = TRUE;
         try {
             $request = \Drupal::request();
             $clean_urls = RequestHelper::isCleanUrl($request);
         } catch (ServiceNotFoundException $e) {
         }
     }
     // If not using clean URLs, the image derivative callback is only available
     // with the script path. If the file does not exist, use url() to ensure
     // that it is included. Once the file exists it's fine to fall back to the
     // actual file path, this avoids bootstrapping PHP once the files are built.
     if ($clean_urls === FALSE && file_uri_scheme($uri) == 'public' && !file_exists($uri)) {
         $directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath();
         return url($directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE, 'query' => $token_query));
     }
     $file_url = file_create_url($uri);
     // Append the query string with the token, if necessary.
     if ($token_query) {
         $file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($token_query);
     }
     return $file_url;
 }
コード例 #26
0
 /**
  * Tests building an image style URL.
  */
 function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_slash = FALSE)
 {
     $this->prepareRequestForGenerator($clean_url);
     // Make the default scheme neither "public" nor "private" to verify the
     // functions work for other than the default scheme.
     $this->config('system.file')->set('default_scheme', 'temporary')->save();
     // Create the directories for the styles.
     $directory = $scheme . '://styles/' . $this->style->id();
     $status = file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
     $this->assertNotIdentical(FALSE, $status, 'Created the directory for the generated images for the test style.');
     // Create a working copy of the file.
     $files = $this->drupalGetTestFiles('image');
     $file = array_shift($files);
     $original_uri = file_unmanaged_copy($file->uri, $scheme . '://', FILE_EXISTS_RENAME);
     // Let the image_module_test module know about this file, so it can claim
     // ownership in hook_file_download().
     \Drupal::state()->set('image.test_file_download', $original_uri);
     $this->assertNotIdentical(FALSE, $original_uri, 'Created the generated image file.');
     // Get the URL of a file that has not been generated and try to create it.
     $generated_uri = $this->style->buildUri($original_uri);
     $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
     $generate_url = $this->style->buildUrl($original_uri, $clean_url);
     // Ensure that the tests still pass when the file is generated by accessing
     // a poorly constructed (but still valid) file URL that has an extra slash
     // in it.
     if ($extra_slash) {
         $modified_uri = str_replace('://', ':///', $original_uri);
         $this->assertNotEqual($original_uri, $modified_uri, 'An extra slash was added to the generated file URI.');
         $generate_url = $this->style->buildUrl($modified_uri, $clean_url);
     }
     if (!$clean_url) {
         $this->assertTrue(strpos($generate_url, 'index.php/') !== FALSE, 'When using non-clean URLS, the system path contains the script name.');
     }
     // Add some extra chars to the token.
     $this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', IMAGE_DERIVATIVE_TOKEN . '=Zo', $generate_url));
     $this->assertResponse(403, 'Image was inaccessible at the URL with an invalid token.');
     // Change the parameter name so the token is missing.
     $this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', 'wrongparam=', $generate_url));
     $this->assertResponse(403, 'Image was inaccessible at the URL with a missing token.');
     // Check that the generated URL is the same when we pass in a relative path
     // rather than a URI. We need to temporarily switch the default scheme to
     // match the desired scheme before testing this, then switch it back to the
     // "temporary" scheme used throughout this test afterwards.
     $this->config('system.file')->set('default_scheme', $scheme)->save();
     $relative_path = file_uri_target($original_uri);
     $generate_url_from_relative_path = $this->style->buildUrl($relative_path, $clean_url);
     $this->assertEqual($generate_url, $generate_url_from_relative_path);
     $this->config('system.file')->set('default_scheme', 'temporary')->save();
     // Fetch the URL that generates the file.
     $this->drupalGet($generate_url);
     $this->assertResponse(200, 'Image was generated at the URL.');
     $this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
     $this->assertRaw(file_get_contents($generated_uri), 'URL returns expected file.');
     $image = $this->container->get('image.factory')->get($generated_uri);
     $this->assertEqual($this->drupalGetHeader('Content-Type'), $image->getMimeType(), 'Expected Content-Type was reported.');
     $this->assertEqual($this->drupalGetHeader('Content-Length'), $image->getFileSize(), 'Expected Content-Length was reported.');
     if ($scheme == 'private') {
         $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
         $this->assertNotEqual(strpos($this->drupalGetHeader('Cache-Control'), 'no-cache'), FALSE, 'Cache-Control header contains \'no-cache\' to prevent caching.');
         $this->assertEqual($this->drupalGetHeader('X-Image-Owned-By'), 'image_module_test', 'Expected custom header has been added.');
         // Make sure that a second request to the already existing derivative
         // works too.
         $this->drupalGet($generate_url);
         $this->assertResponse(200, 'Image was generated at the URL.');
         // Make sure that access is denied for existing style files if we do not
         // have access.
         \Drupal::state()->delete('image.test_file_download');
         $this->drupalGet($generate_url);
         $this->assertResponse(403, 'Confirmed that access is denied for the private image style.');
         // Repeat this with a different file that we do not have access to and
         // make sure that access is denied.
         $file_noaccess = array_shift($files);
         $original_uri_noaccess = file_unmanaged_copy($file_noaccess->uri, $scheme . '://', FILE_EXISTS_RENAME);
         $generated_uri_noaccess = $scheme . '://styles/' . $this->style->id() . '/' . $scheme . '/' . drupal_basename($original_uri_noaccess);
         $this->assertFalse(file_exists($generated_uri_noaccess), 'Generated file does not exist.');
         $generate_url_noaccess = $this->style->buildUrl($original_uri_noaccess);
         $this->drupalGet($generate_url_noaccess);
         $this->assertResponse(403, 'Confirmed that access is denied for the private image style.');
         // Verify that images are not appended to the response. Currently this test only uses PNG images.
         if (strpos($generate_url, '.png') === FALSE) {
             $this->fail('Confirming that private image styles are not appended require PNG file.');
         } else {
             // Check for PNG-Signature (cf. http://www.libpng.org/pub/png/book/chapter08.html#png.ch08.div.2) in the
             // response body.
             $this->assertNoRaw(chr(137) . chr(80) . chr(78) . chr(71) . chr(13) . chr(10) . chr(26) . chr(10), 'No PNG signature found in the response body.');
         }
     } else {
         $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
         $this->assertEqual(strpos($this->drupalGetHeader('Cache-Control'), 'no-cache'), FALSE, 'Cache-Control header contains \'no-cache\' to prevent caching.');
         if ($clean_url) {
             // Add some extra chars to the token.
             $this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', IMAGE_DERIVATIVE_TOKEN . '=Zo', $generate_url));
             $this->assertResponse(200, 'Existing image was accessible at the URL with an invalid token.');
         }
     }
     // Allow insecure image derivatives to be created for the remainder of this
     // test.
     $this->config('image.settings')->set('allow_insecure_derivatives', TRUE)->save();
     // Create another working copy of the file.
     $files = $this->drupalGetTestFiles('image');
     $file = array_shift($files);
     $original_uri = file_unmanaged_copy($file->uri, $scheme . '://', FILE_EXISTS_RENAME);
     // Let the image_module_test module know about this file, so it can claim
     // ownership in hook_file_download().
     \Drupal::state()->set('image.test_file_download', $original_uri);
     // Suppress the security token in the URL, then get the URL of a file that
     // has not been created and try to create it. Check that the security token
     // is not present in the URL but that the image is still accessible.
     $this->config('image.settings')->set('suppress_itok_output', TRUE)->save();
     $generated_uri = $this->style->buildUri($original_uri);
     $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
     $generate_url = $this->style->buildUrl($original_uri, $clean_url);
     $this->assertIdentical(strpos($generate_url, IMAGE_DERIVATIVE_TOKEN . '='), FALSE, 'The security token does not appear in the image style URL.');
     $this->drupalGet($generate_url);
     $this->assertResponse(200, 'Image was accessible at the URL with a missing token.');
     // Stop supressing the security token in the URL.
     $this->config('image.settings')->set('suppress_itok_output', FALSE)->save();
     // Ensure allow_insecure_derivatives is enabled.
     $this->assertEqual($this->config('image.settings')->get('allow_insecure_derivatives'), TRUE);
     // Check that a security token is still required when generating a second
     // image derivative using the first one as a source.
     $nested_url = $this->style->buildUrl($generated_uri, $clean_url);
     $matches_expected_url_format = (bool) preg_match('/styles\\/' . $this->style->id() . '\\/' . $scheme . '\\/styles\\/' . $this->style->id() . '\\/' . $scheme . '/', $nested_url);
     $this->assertTrue($matches_expected_url_format, "URL for a derivative of an image style matches expected format.");
     $nested_url_with_wrong_token = str_replace(IMAGE_DERIVATIVE_TOKEN . '=', 'wrongparam=', $nested_url);
     $this->drupalGet($nested_url_with_wrong_token);
     $this->assertResponse(403, 'Image generated from an earlier derivative was inaccessible at the URL with a missing token.');
     // Check that this restriction cannot be bypassed by adding extra slashes
     // to the URL.
     $this->drupalGet(substr_replace($nested_url_with_wrong_token, '//styles/', strrpos($nested_url_with_wrong_token, '/styles/'), strlen('/styles/')));
     $this->assertResponse(403, 'Image generated from an earlier derivative was inaccessible at the URL with a missing token, even with an extra forward slash in the URL.');
     $this->drupalGet(substr_replace($nested_url_with_wrong_token, '////styles/', strrpos($nested_url_with_wrong_token, '/styles/'), strlen('/styles/')));
     $this->assertResponse(403, 'Image generated from an earlier derivative was inaccessible at the URL with a missing token, even with multiple forward slashes in the URL.');
     // Make sure the image can still be generated if a correct token is used.
     $this->drupalGet($nested_url);
     $this->assertResponse(200, 'Image was accessible when a correct token was provided in the URL.');
     // Check that requesting a nonexistent image does not create any new
     // directories in the file system.
     $directory = $scheme . '://styles/' . $this->style->id() . '/' . $scheme . '/' . $this->randomMachineName();
     $this->drupalGet(file_create_url($directory . '/' . $this->randomString()));
     $this->assertFalse(file_exists($directory), 'New directory was not created in the filesystem when requesting an unauthorized image.');
 }
コード例 #27
0
ファイル: theme-settings.php プロジェクト: pantasio/hdso
/**
 * Implements hook_form_system_theme_settings_alter()
 */
function jollyany_form_system_theme_settings_alter(&$form, &$form_state)
{
    $contact_icon = theme_get_setting('contact_icon');
    if (file_uri_scheme($contact_icon) == 'public') {
        $contact_icon = file_uri_target($contact_icon);
    }
    // Main settings wrapper
    $form['options'] = array('#type' => 'vertical_tabs', '#default_tab' => 'defaults', '#weight' => '-10', '#attached' => array('css' => array(drupal_get_path('theme', 'jollyany') . '/css/theme-options.css')));
    // ----------- General -----------
    $form['options']['general'] = array('#type' => 'fieldset', '#title' => t('General'));
    // Breadcrumbs
    $form['options']['general']['breadcrumbs'] = array('#type' => 'checkbox', '#title' => 'Show Breadcrumbs', '#default_value' => theme_get_setting('breadcrumbs'));
    // Contact MAP
    $form['options']['general']['contactmap'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Contact Map</h3>');
    // Company Name
    $form['options']['general']['contactmap']['contactmap_title'] = array('#type' => 'textfield', '#title' => 'Company Name', '#default_value' => theme_get_setting('contactmap_title'));
    // Website
    $form['options']['general']['contactmap']['contactmap_website'] = array('#type' => 'textfield', '#title' => 'Website', '#default_value' => theme_get_setting('contactmap_website'));
    // Contact MAP Address
    $form['options']['general']['contactmap']['contactmap_address'] = array('#type' => 'textarea', '#title' => 'Address', '#default_value' => theme_get_setting('contactmap_address'));
    // Contact MAP Phone
    $form['options']['general']['contactmap']['contactmap_phone'] = array('#type' => 'textfield', '#title' => 'Telephone', '#default_value' => theme_get_setting('contactmap_phone'));
    // Contact MAP Lat
    $form['options']['general']['contactmap']['contactmap_lat'] = array('#type' => 'textfield', '#title' => 'Lat', '#default_value' => theme_get_setting('contactmap_lat'));
    // Contact MAP Long
    $form['options']['general']['contactmap']['contactmap_long'] = array('#type' => 'textfield', '#title' => 'Long', '#default_value' => theme_get_setting('contactmap_long'));
    $form['options']['general']['contactmap']['contact_icon'] = array('#type' => 'textfield', '#title' => 'Path to Contact Icon', '#default_value' => $contact_icon, '#disabled' => TRUE);
    $form['options']['general']['contactmap']['contact_icon_upload'] = array('#type' => 'file', '#title' => 'Upload Contact Icon', '#description' => 'Upload a new Contact Icon.');
    // -------- SEO ---------
    $form['options']['general']['seo'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">SEO</h3>');
    // SEO Title
    $form['options']['general']['seo']['seo_title'] = array('#type' => 'textfield', '#title' => 'Title', '#default_value' => theme_get_setting('seo_title'));
    // SEO Description
    $form['options']['general']['seo']['seo_description'] = array('#type' => 'textarea', '#title' => 'Description', '#default_value' => theme_get_setting('seo_description'));
    // SEO Keywords
    $form['options']['general']['seo']['seo_keywords'] = array('#type' => 'textarea', '#title' => 'Keywords', '#default_value' => theme_get_setting('seo_keywords'));
    // ----------- Layout -----------
    $form['options']['layout'] = array('#type' => 'fieldset', '#title' => t('Layout'));
    // ------ Page Layout Settings ------
    $form['options']['layout']['page'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Page Layout Settings</h3>');
    //Page Layout Container
    $form['options']['layout']['page']['page_style1'] = array('#type' => 'textarea', '#title' => 'Page Style: Boxed Layout - Topbar (Example Home Version 7)', '#default_value' => theme_get_setting('page_style1'));
    //Page Layout Container
    $form['options']['layout']['page']['page_style2'] = array('#type' => 'textarea', '#title' => 'Page Style: Boxed Layout (Example Home Version 8)', '#default_value' => theme_get_setting('page_style2'));
    //Page Layout Container
    $form['options']['layout']['page']['page_onepage'] = array('#type' => 'textarea', '#title' => 'Page Style: One Page', '#default_value' => theme_get_setting('page_onepage'));
    //Page Layout Container
    $form['options']['layout']['page']['page_only_content'] = array('#type' => 'textarea', '#title' => 'Page Style: Only content Layout (Example 404 page)', '#default_value' => theme_get_setting('page_only_content'));
    // ------ Header Settings ------
    $form['options']['layout']['header'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Header Page Settings</h3>');
    $form['options']['layout']['header']['header_1'] = array('#type' => 'textarea', '#title' => 'Page With Header Style 1', '#default_value' => theme_get_setting('header_1'));
    $form['options']['layout']['header']['header_2'] = array('#type' => 'textarea', '#title' => 'Page With Header Style 2', '#default_value' => theme_get_setting('header_2'));
    $form['options']['layout']['header']['header_3'] = array('#type' => 'textarea', '#title' => 'Page With Header Style 3', '#default_value' => theme_get_setting('header_3'));
    // ------ Footer Settings ------
    $form['options']['layout']['footer'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Footer Page Settings</h3>');
    $form['options']['layout']['footer']['footer_1'] = array('#type' => 'textarea', '#title' => 'Page With Footer Style 1', '#default_value' => theme_get_setting('footer_1'));
    $form['options']['layout']['footer']['footer_2'] = array('#type' => 'textarea', '#title' => 'Page With Footer Style 2', '#default_value' => theme_get_setting('footer_2'));
    $form['options']['layout']['footer']['footer_3'] = array('#type' => 'textarea', '#title' => 'Page With Footer Style 3', '#default_value' => theme_get_setting('footer_3'));
    // -------- Projects Layout Settings ----------
    $form['options']['layout']['projects'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Projects Page Layout</h3>');
    // View Project Text Button
    $form['options']['layout']['projects']['project_text_button'] = array('#type' => 'textfield', '#title' => 'View Project Text Button', '#default_value' => theme_get_setting('project_text_button'));
    $form['options']['layout']['projects']['projects_fulllayout'] = array('#type' => 'textarea', '#title' => 'Projects Page Style: Full Layout', '#default_value' => theme_get_setting('projects_fulllayout'));
    // Projects Layout
    /*$form['options']['layout']['projects']['projects_layout'] = array(
           '#type' => 'radios',
           '#title' => 'Select a projects layout:',
           '#default_value' => theme_get_setting('projects_layout'),
           '#options' => array(
               '2_columns' => '2 Columns',
               '3_columns' => '3 Columns',
               '4_columns' => '4 Columns (default)',
    		'2_columns_boxed' => '2 Columns Boxed',
               '3_columns_boxed' => '3 Columns Boxed',
               '4_columns_boxed' => '4 Columns Boxed',
    		'3_columns_full' => '3 Columns Full Width',
               '4_columns_full' => '4 Columns Full Width',
               '6_columns_full' => '6 Columns Full Width',
           ),
       );*/
    // ------- Blog Layout Settings ----------
    /*$form['options']['layout']['blog'] = array(
            '#type' => 'fieldset',
            '#title' => '<div class="plus"></div><h3 class="options_heading">Blog Page Layout</h3>',
        );
    	
        // Blog Layout
        $form['options']['layout']['blog']['blog_layout'] = array(
            '#type' => 'radios',
            '#title' => 'Select a blog layout:',
            '#default_value' => theme_get_setting('blog_layout'),
            '#options' => array(
                'sidebar_right' => 'Sidebar Right (default)',
                'full_width' => 'Full Width',
            ),
        );*/
    /*
    // --------- Contact Layout Settings ----------
        $form['options']['layout']['contact'] = array(
            '#type' => 'fieldset',
            '#title' => '<div class="plus"></div><h3 class="options_heading">Contact Page Layout</h3>',
        );
    
        // Contact Layout
        $form['options']['layout']['contact']['contact_layout'] = array(
            '#type' => 'radios',
            '#title' => 'Select a contact layout:',
            '#default_value' => theme_get_setting('contact_layout'),
            '#options' => array(
                'contact-1' => 'Contact 1 (default)',
                'contact-2' => 'Contact 2',
                'contact-3' => 'Contact 3',
            ),
        );
    */
    // ----------- Design  Settings -----------
    $form['options']['design'] = array('#type' => 'fieldset', '#title' => 'Design');
    // Switcher
    $form['options']['design']['switcher'] = array('#type' => 'checkbox', '#title' => 'Show Switcher Control', '#default_value' => theme_get_setting('switcher'));
    // Layout Option
    $form['options']['design']['layout_style'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Layout Style</h3>');
    $form['options']['design']['layout_style']['layout_option'] = array('#type' => 'radios', '#title' => 'Select a layout style:', '#default_value' => theme_get_setting('layout_option'), '#options' => array('boxed' => 'Boxed', 'fullwidth' => 'Full Width (default)'));
    // Header Option
    $form['options']['design']['header_style'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Header Style</h3>');
    // Header Option
    $form['options']['design']['header_style']['header_option'] = array('#type' => 'radios', '#title' => 'Select a header style option:', '#default_value' => theme_get_setting('header_option'), '#options' => array('header_default' => 'Header Default', 'header1' => 'Header 1', 'header2' => 'Header 2', 'header3' => 'Header 3'));
    // Footer Option
    $form['options']['design']['footer_style'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Footer Style</h3>');
    // Footer Option
    $form['options']['design']['footer_style']['footer_option'] = array('#type' => 'radios', '#title' => 'Select a footer style option:', '#default_value' => theme_get_setting('footer_option'), '#options' => array('footer_default' => 'Footer Default', 'footer1' => 'Footer 1', 'footer2' => 'Footer 2', 'footer3' => 'Footer 3'));
    // Color Option
    $form['options']['design']['color'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Color</h3>');
    // Color Scheme Option
    $form['options']['design']['color']['color_scheme'] = array('#type' => 'select', '#title' => 'Color Scheme', '#default_value' => theme_get_setting('color_scheme'), '#options' => array('blue' => 'Blue', 'green' => 'Green', 'light-blue' => 'Light Blue', 'light-green' => 'Light Green', 'orange' => 'Orange', 'green' => 'Green', 'purple' => 'Purple', 'red' => 'Red', 'tael' => 'Tael', 'violet' => 'Violet', 'yellow' => 'Yellow (default)'));
    // Background Option
    $form['options']['design']['background'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Background</h3>');
    // Background Color Option
    $form['options']['design']['background']['background_style'] = array('#type' => 'radios', '#title' => 'Select a background style:', '#default_value' => theme_get_setting('background_style'), '#options' => array('light' => 'Light (default)', 'dark' => 'Dark'));
    // CSS
    $form['options']['design']['css'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">CSS</h3>');
    // User CSS
    $form['options']['design']['css']['user_css'] = array('#type' => 'textarea', '#title' => 'Add your own CSS', '#default_value' => theme_get_setting('user_css'));
    // Submit Button
    $form['#submit'][] = 'jollyany_settings_submit';
}
コード例 #28
0
 /**
  * Provides a wrapper for file_uri_target() to allow unit testing.
  *
  * Returns the part of a URI after the schema.
  *
  * @param string $uri
  *   A stream, referenced as "scheme://target" or "data:target".
  *
  * @see file_uri_scheme()
  *
  * @todo: Convert file_uri_target() into a proper injectable service.
  *
  * @return string|bool
  *   A string containing the target (path), or FALSE if none.
  *   For example, the URI "public://sample/test.txt" would return
  *   "sample/test.txt".
  */
 protected function fileUriTarget($uri)
 {
     return file_uri_target($uri);
 }
コード例 #29
0
ファイル: ThemeSettingsForm.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  *
  * @param string $theme
  *   The theme name.
  */
 public function buildForm(array $form, FormStateInterface $form_state, $theme = '')
 {
     $form = parent::buildForm($form, $form_state);
     $themes = $this->themeHandler->listInfo();
     // Default settings are defined in theme_get_setting() in includes/theme.inc
     if ($theme) {
         if (!$this->themeHandler->hasUi($theme)) {
             throw new NotFoundHttpException();
         }
         $var = 'theme_' . $theme . '_settings';
         $config_key = $theme . '.settings';
         $themes = $this->themeHandler->listInfo();
         $features = $themes[$theme]->info['features'];
     } else {
         $var = 'theme_settings';
         $config_key = 'system.theme.global';
     }
     // @todo this is pretty meaningless since we're using theme_get_settings
     //   which means overrides can bleed into active config here. Will be fixed
     //   by https://www.drupal.org/node/2402467.
     $this->editableConfig = [$config_key];
     $form['var'] = array('#type' => 'hidden', '#value' => $var);
     $form['config_key'] = array('#type' => 'hidden', '#value' => $config_key);
     // Toggle settings
     $toggles = array('node_user_picture' => t('User pictures in posts'), 'comment_user_picture' => t('User pictures in comments'), 'comment_user_verification' => t('User verification status in comments'), 'favicon' => t('Shortcut icon'));
     // Some features are not always available
     $disabled = array();
     if (!user_picture_enabled()) {
         $disabled['toggle_node_user_picture'] = TRUE;
         $disabled['toggle_comment_user_picture'] = TRUE;
     }
     if (!$this->moduleHandler->moduleExists('comment')) {
         $disabled['toggle_comment_user_picture'] = TRUE;
         $disabled['toggle_comment_user_verification'] = TRUE;
     }
     $form['theme_settings'] = array('#type' => 'details', '#title' => t('Toggle display'), '#open' => TRUE, '#description' => t('Enable or disable the display of certain page elements.'));
     foreach ($toggles as $name => $title) {
         if (!$theme || in_array($name, $features)) {
             $form['theme_settings']['toggle_' . $name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => theme_get_setting('features.' . $name, $theme));
             // Disable checkboxes for features not supported in the current configuration.
             if (isset($disabled['toggle_' . $name])) {
                 $form['theme_settings']['toggle_' . $name]['#disabled'] = TRUE;
             }
         }
     }
     if (!Element::children($form['theme_settings'])) {
         // If there is no element in the theme settings details then do not show
         // it -- but keep it in the form if another module wants to alter.
         $form['theme_settings']['#access'] = FALSE;
     }
     // Logo settings, only available when file.module is enabled.
     if (!$theme || in_array('logo', $features) && $this->moduleHandler->moduleExists('file')) {
         $form['logo'] = array('#type' => 'details', '#title' => t('Logo image settings'), '#open' => TRUE, '#states' => array('invisible' => array('input[name="toggle_logo"]' => array('checked' => FALSE))));
         $form['logo']['default_logo'] = array('#type' => 'checkbox', '#title' => t('Use the default logo supplied by the theme'), '#default_value' => theme_get_setting('logo.use_default', $theme), '#tree' => FALSE);
         $form['logo']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="default_logo"]' => array('checked' => TRUE))));
         $form['logo']['settings']['logo_path'] = array('#type' => 'textfield', '#title' => t('Path to custom logo'), '#default_value' => theme_get_setting('logo.path', $theme));
         $form['logo']['settings']['logo_upload'] = array('#type' => 'file', '#title' => t('Upload logo image'), '#maxlength' => 40, '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."));
     }
     if ((!$theme || in_array('favicon', $features)) && $this->moduleHandler->moduleExists('file')) {
         $form['favicon'] = array('#type' => 'details', '#title' => t('Shortcut icon settings'), '#open' => TRUE, '#description' => t("Your shortcut icon, or 'favicon', is displayed in the address bar and bookmarks of most browsers."), '#states' => array('invisible' => array('input[name="toggle_favicon"]' => array('checked' => FALSE))));
         $form['favicon']['default_favicon'] = array('#type' => 'checkbox', '#title' => t('Use the default shortcut icon supplied by the theme'), '#default_value' => theme_get_setting('favicon.use_default', $theme));
         $form['favicon']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="default_favicon"]' => array('checked' => TRUE))));
         $form['favicon']['settings']['favicon_path'] = array('#type' => 'textfield', '#title' => t('Path to custom icon'), '#default_value' => theme_get_setting('favicon.path', $theme));
         $form['favicon']['settings']['favicon_upload'] = array('#type' => 'file', '#title' => t('Upload icon image'), '#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon."));
     }
     // Inject human-friendly values and form element descriptions for logo and
     // favicon.
     foreach (array('logo' => 'logo.svg', 'favicon' => 'favicon.ico') as $type => $default) {
         if (isset($form[$type]['settings'][$type . '_path'])) {
             $element =& $form[$type]['settings'][$type . '_path'];
             // If path is a public:// URI, display the path relative to the files
             // directory; stream wrappers are not end-user friendly.
             $original_path = $element['#default_value'];
             $friendly_path = NULL;
             if (file_uri_scheme($original_path) == 'public') {
                 $friendly_path = file_uri_target($original_path);
                 $element['#default_value'] = $friendly_path;
             }
             // Prepare local file path for description.
             if ($original_path && isset($friendly_path)) {
                 $local_file = strtr($original_path, array('public:/' => PublicStream::basePath()));
             } elseif ($theme) {
                 $local_file = drupal_get_path('theme', $theme) . '/' . $default;
             } else {
                 $local_file = \Drupal::theme()->getActiveTheme()->getPath() . '/' . $default;
             }
             $element['#description'] = t('Examples: <code>@implicit-public-file</code> (for a file in the public filesystem), <code>@explicit-file</code>, or <code>@local-file</code>.', array('@implicit-public-file' => isset($friendly_path) ? $friendly_path : $default, '@explicit-file' => file_uri_scheme($original_path) !== FALSE ? $original_path : 'public://' . $default, '@local-file' => $local_file));
         }
     }
     if ($theme) {
         // Call engine-specific settings.
         $function = $themes[$theme]->prefix . '_engine_settings';
         if (function_exists($function)) {
             $form['engine_specific'] = array('#type' => 'details', '#title' => t('Theme-engine-specific settings'), '#open' => TRUE, '#description' => t('These settings only exist for the themes based on the %engine theme engine.', array('%engine' => $themes[$theme]->prefix)));
             $function($form, $form_state);
         }
         // Create a list which includes the current theme and all its base themes.
         if (isset($themes[$theme]->base_themes)) {
             $theme_keys = array_keys($themes[$theme]->base_themes);
             $theme_keys[] = $theme;
         } else {
             $theme_keys = array($theme);
         }
         // Save the name of the current theme (if any), so that we can temporarily
         // override the current theme and allow theme_get_setting() to work
         // without having to pass the theme name to it.
         $default_active_theme = \Drupal::theme()->getActiveTheme();
         $default_theme = $default_active_theme->getName();
         /** @var \Drupal\Core\Theme\ThemeInitialization $theme_initialization */
         $theme_initialization = \Drupal::service('theme.initialization');
         \Drupal::theme()->setActiveTheme($theme_initialization->getActiveThemeByName($theme));
         // Process the theme and all its base themes.
         foreach ($theme_keys as $theme) {
             // Include the theme-settings.php file.
             $filename = DRUPAL_ROOT . '/' . $themes[$theme]->getPath() . '/theme-settings.php';
             if (file_exists($filename)) {
                 require_once $filename;
             }
             // Call theme-specific settings.
             $function = $theme . '_form_system_theme_settings_alter';
             if (function_exists($function)) {
                 $function($form, $form_state);
             }
         }
         // Restore the original current theme.
         if (isset($default_theme)) {
             \Drupal::theme()->setActiveTheme($default_active_theme);
         } else {
             \Drupal::theme()->resetActiveTheme();
         }
     }
     return $form;
 }
コード例 #30
0
ファイル: FileItemTest.php プロジェクト: eigentor/tommiblog
 /**
  * Tests using entity fields of the file field type.
  */
 public function testFileItem()
 {
     // Check that the selection handler was automatically assigned to
     // 'default:file'.
     $field_definition = FieldConfig::load('entity_test.entity_test.file_test');
     $handler_id = $field_definition->getSetting('handler');
     $this->assertEqual($handler_id, 'default:file');
     // Create a test entity with the
     $entity = EntityTest::create();
     $entity->file_test->target_id = $this->file->id();
     $entity->file_test->display = 1;
     $entity->file_test->description = $description = $this->randomMachineName();
     $entity->name->value = $this->randomMachineName();
     $entity->save();
     $entity = EntityTest::load($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->randomMachineName());
     $file2 = File::create(['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();
     // Test the generateSampleValue() method.
     $entity = EntityTest::create();
     $entity->file_test->generateSampleItems();
     $this->entityValidateAndSave($entity);
     // Verify that the sample file was stored in the correct directory.
     $uri = $entity->file_test->entity->getFileUri();
     $this->assertEqual($this->directory, dirname(file_uri_target($uri)));
     // Make sure the computed files reflects updates to the file.
     file_put_contents('public://example-3.txt', $this->randomMachineName());
     // Test unsaved file entity.
     $file3 = File::create(['uri' => 'public://example-3.txt']);
     $display = entity_get_display('entity_test', 'entity_test', 'default');
     $display->setComponent('file_test', ['label' => 'above', 'type' => 'file_default', 'weight' => 1])->save();
     $entity = EntityTest::create();
     $entity->file_test = array('entity' => $file3);
     $uri = $file3->getFileUri();
     $output = entity_view($entity, 'default');
     \Drupal::service('renderer')->renderRoot($output);
     $this->assertTrue(!empty($entity->file_test->entity));
     $this->assertEqual($entity->file_test->entity->getFileUri(), $uri);
 }