/**
  * {@inheritdoc}
  */
 public function generate(array $packages = array(), FeaturesBundleInterface $bundle = NULL)
 {
     $filename = isset($bundle) && $bundle->isProfile() ? $bundle->getProfileName() : 'generated_features';
     // If no packages were specified, get all packages.
     if (empty($packages)) {
         $packages = $this->featuresManager->getPackages();
     } elseif (count($packages) == 1) {
         // Single package export, so name tar archive by package name.
         $filename = current($packages)['machine_name'];
     }
     $return = [];
     $this->archiveName = $filename . '.tar.gz';
     $archive_name = file_directory_temp() . '/' . $this->archiveName;
     if (file_exists($archive_name)) {
         file_unmanaged_delete($archive_name);
     }
     $archiver = new ArchiveTar($archive_name);
     // Add package files.
     foreach ($packages as $package) {
         if (count($packages) == 1) {
             // Single module export, so don't generate entire modules dir structure.
             $package['directory'] = $package['machine_name'];
         }
         $this->generatePackage($return, $package, $archiver);
     }
     return $return;
 }
 /**
  * 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');
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $messageHelper = $this->getHelperSet()->get('message');
     $directory = $input->getArgument('directory');
     if (!$directory) {
         $config = $this->getConfigFactory()->get('system.file');
         $directory = $config->get('path.temporary') ?: file_directory_temp();
         $directory .= '/' . CONFIG_STAGING_DIRECTORY;
     }
     if (!is_dir($directory)) {
         mkdir($directory, 0777, true);
     }
     $config_export_file = $directory . '/config.tar.gz';
     file_unmanaged_delete($config_export_file);
     try {
         $archiver = new ArchiveTar($config_export_file, 'gz');
         $this->configManager = $this->getConfigManager();
         // Get raw configuration data without overrides.
         foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
             $archiver->addString("{$name}.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData()));
         }
         $this->targetStorage = $this->getConfigStorage();
         // Get all override data from the remaining collections.
         foreach ($this->targetStorage->getAllCollectionNames() as $collection) {
             $collection_storage = $this->targetStorage->createCollection($collection);
             foreach ($collection_storage->listAll() as $name) {
                 $archiver->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage->read($name)));
             }
         }
     } catch (\Exception $e) {
         $output->writeln('[+] <error>' . $e->getMessage() . '</error>');
         return;
     }
     $messageHelper->addSuccessMessage(sprintf($this->trans('commands.config.export.messages.directory'), $config_export_file));
 }
Пример #4
0
 /**
  * 'upload_zip' upload field must refer to a zip file containing 
  *   all files for the pubnode (may be at top-level or inside a subdirectory)
  */
 public function import(&$form_state, $docid = NULL)
 {
     $validators = array('file_validate_extensions' => array('zip'), 'file_validate_size' => array(100000000, 0));
     if ($file = file_save_upload($this->fieldname, $validators, file_directory_temp(), FILE_EXISTS_REPLACE)) {
         $zip = new ZipArchive();
         if ($zip->open($file->filepath) !== TRUE) {
             form_set_error(t("Cannot open !file", array("!file" => $file->filename)), 'error');
             return FALSE;
         }
         // else
         if (empty($docid)) {
             $docid = $this->hashFile($file->filepath);
         }
         $pubpath = $this->constructPubPath($docid);
         //drupal_set_message("PUBPATH: " . $pubpath);
         file_check_directory($pubpath, FILE_CREATE_DIRECTORY);
         $zip->extractTo($pubpath);
         drupal_set_message(t("Extracted !num files to directory !dir", array('!num' => $zip->numFiles, '!dir' => $pubpath)));
         $zip->close();
         $this->pubpath = $pubpath;
         return TRUE;
     }
     // else validations failed and error message will be set by upload function
     return FALSE;
 }
 /**
  * Set the hooks directory.
  */
 function getHooksDirectorySetting()
 {
     // Set the folder for the hooks. This contains a prepared file for the tests
     // to use.
     // By some magic this appears to be safe to use with DrupalUnitTestCase.
     $directory = file_directory_temp() . '/module_builder_hook_definitions/' . $this->major_version;
     $this->hooks_directory = $directory;
 }
Пример #6
0
 public function testExportArchive()
 {
     $filename = file_directory_temp() . '/' . self::PACKAGE_NAME . '.tar.gz';
     if (file_exists($filename)) {
         unlink($filename);
     }
     $this->assertFalse(file_exists($filename), 'Archive file already exists.');
     $this->generator->generatePackages('archive', [self::PACKAGE_NAME], $this->assigner->getBundle());
     $this->assertTrue(file_exists($filename), 'Archive file was not generated.');
 }
Пример #7
0
 /**
  * Create a file with the specified data.
  *
  * @param $data
  *   Twodimensional array.
  *
  * @param $file_options
  *   Array with record separator, etc.
  *
  * @return
  *   String. Path to file (in temporary directory).
  */
 public function nodeImportCreateFile($data, $file_options = array())
 {
     module_load_include('inc', 'node_import');
     $path = file_create_filename($this->randomName() . '.csv', file_directory_temp());
     $fp = fopen($path, 'w');
     foreach ($data as $row) {
         $s = node_import_write_to_string($row, $file_options);
         fputs($fp, $s);
     }
     fclose($fp);
     return $path;
 }
Пример #8
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);
 }
 /**
  * @covers \Drupal\features\FeaturesGenerator::setPackageBundleNames
  */
 public function testGeneratorWithBundle()
 {
     $filename = file_directory_temp() . '/giraffe_' . self::PACKAGE_NAME . '.tar.gz';
     if (file_exists($filename)) {
         unlink($filename);
     }
     $this->assertFalse(file_exists($filename), 'Archive file already exists.');
     $bundle = FeaturesBundle::create(['machine_name' => 'giraffe']);
     $this->generator->generatePackages('archive', [self::PACKAGE_NAME], $bundle);
     $package = $this->featuresManager->getPackage(self::PACKAGE_NAME);
     $this->assertNull($package);
     $package = $this->featuresManager->getPackage('giraffe_' . self::PACKAGE_NAME);
     $this->assertEquals('giraffe_' . self::PACKAGE_NAME, $package->getMachineName());
     $this->assertEquals('giraffe', $package->getBundle());
     $this->assertTrue(file_exists($filename), 'Archive file was not generated.');
 }
Пример #10
0
 /**
  * Downloads a tarball of the site configuration.
  */
 public function downloadExport()
 {
     file_unmanaged_delete(file_directory_temp() . '/config.tar.gz');
     $archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz');
     // Get raw configuration data without overrides.
     foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
         $archiver->addString("{$name}.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData()));
     }
     // Get all override data from the remaining collections.
     foreach ($this->targetStorage->getAllCollectionNames() as $collection) {
         $collection_storage = $this->targetStorage->createCollection($collection);
         foreach ($collection_storage->listAll() as $name) {
             $archiver->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage->read($name)));
         }
     }
     $request = new Request(array('file' => 'config.tar.gz'));
     return $this->fileDownloadController->download($request, 'temporary');
 }
Пример #11
0
 /**
  * (non-PHPdoc)
  * @see Yamm_FileFetcher::_fetch()
  */
 public function _fetch($filepath)
 {
     $source_url = yamm_api_clean_url($this->_server->getUrl()) . $filepath;
     // Get file contents.
     if ($data = file_get_contents($source_url, FILE_BINARY)) {
         // Get a new temporary file name, for file creation.
         $tmp = file_directory_temp() . '/' . uniqid('yamm-');
         // If we go some content, return new file path as data.
         if (file_put_contents($tmp, $data) > 0) {
             // Free up some memory after copy.
             unset($data);
             return $tmp;
         } else {
             throw new Yamm_FileFetcher_CouldNotFetchException("Unable to save " . $source_url . " downloaded file as temporary file");
         }
     } else {
         throw new Yamm_FileFetcher_CouldNotFetchException("Unable to download file " . $source_url);
     }
 }
Пример #12
0
function resizeimage_wrapper_filecache()
{
    global $bgcachexpire;
    $bgcacheid = 'bg_' . md5($_GET['imgp'] . $_GET['imgw'] . $_GET['imgh']);
    #echo $bgcacheid;
    #echo '. 0.... ';
    # Tested that both relative (eg sites/all/files/cache) and absolute (eg /home/data/tmp) tmp path settings work OK here.
    $cachetemp = variable_get('brilliant_gallery_pcache', file_directory_temp());
    #$cachedfile = file_directory_temp() .'/'. $bgcacheid;
    $cachedfile = $cachetemp . '/' . $bgcacheid;
    #$cachedfile = realpath(file_directory_temp() . '/' . $bgcacheid);
    #echo file_directory_temp()  . '/' . $bgcacheid;
    #echo " .... ";
    #echo $cachedfile;
    # See http://drupal.org/node/194923
    $lastchanged = file_exists($cachedfile) ? filemtime($cachedfile) : false;
    if ($lastchanged === false or time() - $lastchanged > $bgcachexpire) {
        #echo '. 1.... ';
        # Cache file does not exist or is too old.
        $my_data = resizeimage($_GET['imgp'], $_GET['imgw'], $_GET['imgh']);
        # Now put $my_data to cache!
        $fh = fopen($cachedfile, "w+");
        fwrite($fh, $my_data);
        fclose($fh);
        #test
        /*
        $my_data_t = unserialize( $my_data );
        $fh = fopen( $cachedfile . '_2', "w+" );
         fwrite( $fh, $my_data_t[1] );
         fclose( $fh ); 
        */
        $my_data = unserialize($my_data);
    } else {
        #echo '. 2.... ';
        # Cache file exists.
        $my_data = unserialize(file_get_contents($cachedfile));
    }
    return $my_data;
}
Пример #13
0
 /**
  * Downloads the translated document for the specified document and language.
  *
  * @param int $document_id
  *   The Lingotek document ID that should be downloaded.
  * @param string $language_lingotek
  *   A Lingotek language/locale code.
  *
  * @return mixed
  *   On success, a SimpleXMLElement object representing the translated document. FALSE on failure.
  *
  */
 public function downloadDocument($document_id, $language_lingotek)
 {
     $document = FALSE;
     $params = array('documentId' => $document_id, 'targetLanguage' => $language_lingotek);
     if ($results = $this->request('downloadDocument', $params)) {
         try {
             // TODO: This is borrowed from the now-deprecated LingotekSession::download()
             // and could use refactoring.
             $tmpFile = tempnam(file_directory_temp(), 'lingotek');
             $fp = fopen($tmpFile, 'w');
             fwrite($fp, $results);
             fclose($fp);
             $text = '';
             $file = FALSE;
             // downloadDocument returns zip-encoded data.
             $zip = new ZipArchive();
             $zip->open($tmpFile);
             $name = $zip->getNameIndex(0);
             $file = $zip->getStream($name);
             if ($file) {
                 while (!feof($file)) {
                     $text .= fread($file, 2);
                 }
                 fclose($file);
             }
             unlink($tmpFile);
             $document = new SimpleXMLElement($text);
         } catch (Exception $e) {
             LingotekLog::error('Unable to parse downloaded document. Error: @error. Text: !xml.', array('!xml' => $text, '@error' => $e->getMessage()));
         }
     }
     return $document;
 }
Пример #14
0
 /**
  * BC: Automatically resolve former KernelTestBase class properties.
  *
  * Test authors should follow the provided instructions and adjust their tests
  * accordingly.
  *
  * @deprecated in Drupal 8.0.x, will be removed before Drupal 8.2.0.
  */
 public function __get($name)
 {
     if (in_array($name, array('public_files_directory', 'private_files_directory', 'temp_files_directory', 'translation_files_directory'))) {
         // @comment it in again.
         trigger_error(sprintf("KernelTestBase::\$%s no longer exists. Use the regular API method to retrieve it instead (e.g., Settings).", $name), E_USER_DEPRECATED);
         switch ($name) {
             case 'public_files_directory':
                 return Settings::get('file_public_path', \Drupal::service('site.path') . '/files');
             case 'private_files_directory':
                 return $this->container->get('config.factory')->get('system.file')->get('path.private');
             case 'temp_files_directory':
                 return file_directory_temp();
             case 'translation_files_directory':
                 return Settings::get('file_public_path', \Drupal::service('site.path') . '/translations');
         }
     }
     if ($name === 'configDirectories') {
         trigger_error(sprintf("KernelTestBase::\$%s no longer exists. Use config_get_config_directory() directly instead.", $name), E_USER_DEPRECATED);
         return array(CONFIG_SYNC_DIRECTORY => config_get_config_directory(CONFIG_SYNC_DIRECTORY));
     }
     $denied = array('testId', 'timeLimit', 'results', 'assertions', 'skipClasses', 'verbose', 'verboseId', 'verboseClassName', 'verboseDirectory', 'verboseDirectoryUrl', 'dieOnFail', 'kernel', 'generatedTestFiles', 'keyValueFactory');
     if (in_array($name, $denied) || strpos($name, 'original') === 0) {
         throw new \RuntimeException(sprintf('TestBase::$%s property no longer exists', $name));
     }
 }
Пример #15
0
/**
 * Make changes to a file before it is downloaded by the customer.
 *
 * Stores, either for customization, copy protection or other reasons, might want
 * to send customized downloads to customers. This hook will allow this to happen.
 * Before a file is opened to be transfered to a customer, this hook will be called
 * to make any altercations to the file that will be used to transfer the download
 * to the customer. This, in effect, will allow a developer to create a new,
 * personalized, file that will get transfered to a customer.
 *
 * @param $file_user
 *   The file_user object (i.e. an object containing a row from the uc_file_users
 *   table) that corresponds with the user download being accessed.
 * @param $ip
 *   The IP address from which the customer is downloading the file
 * @param $fid
 *   The file id of the file being transfered
 * @param $file
 *   The file path of the file to be transfered
 * @return
 *   The path of the new file to transfer to customer.
 */
function hook_file_transfer_alter($file_user, $ip, $fid, $file)
{
    $file_data = file_get_contents($file) . " [insert personalized data]";
    //for large files this might be too memory intensive
    $new_file = tempnam(file_directory_temp(), 'tmp');
    file_put_contents($new_file, $file_data);
    return $new_file;
}
Пример #16
0
/**
 * The Drupal installation happens in a series of steps. We begin by verifying
 * that the current environment meets our minimum requirements. We then go
 * on to verify that settings.php is properly configured. From there we
 * connect to the configured database and verify that it meets our minimum
 * requirements. Finally we can allow the user to select an installation
 * profile and complete the installation process.
 *
 * @param $phase
 *   The installation phase we should proceed to.
 */
function install_main()
{
    require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
    // The user agent header is used to pass a database prefix in the request when
    // running tests. However, for security reasons, it is imperative that no
    // installation be permitted using such a prefix.
    if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
        exit;
    }
    // This must go after drupal_bootstrap(), which unsets globals!
    global $profile, $install_locale, $conf;
    require_once DRUPAL_ROOT . '/modules/system/system.install';
    require_once DRUPAL_ROOT . '/includes/file.inc';
    // Ensure correct page headers are sent (e.g. caching)
    drupal_page_header();
    // Set up $language, so t() caller functions will still work.
    drupal_init_language();
    // Load module basics (needed for hook invokes).
    include_once DRUPAL_ROOT . '/includes/module.inc';
    $module_list['system']['filename'] = 'modules/system/system.module';
    $module_list['filter']['filename'] = 'modules/filter/filter.module';
    module_list(TRUE, FALSE, FALSE, $module_list);
    drupal_load('module', 'system');
    drupal_load('module', 'filter');
    // Load the cache infrastructure using a "fake" cache implementation that
    // does not attempt to write to the database. We need this during the initial
    // part of the installer because the database is not available yet. We
    // continue to use it even when the database does become available, in order
    // to preserve consistency between interactive and command-line installations
    // (the latter complete in one page request and therefore are forced to
    // continue using the cache implementation they started with) and also
    // because any data put in the cache during the installer is inherently
    // suspect, due to the fact that Drupal is not fully set up yet.
    require_once DRUPAL_ROOT . '/includes/cache-install.inc';
    $conf['cache_inc'] = './includes/cache-install.inc';
    // Install profile chosen, set the global immediately.
    // This needs to be done before the theme cache gets
    // initialized in drupal_maintenance_theme().
    if (!empty($_GET['profile'])) {
        $profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']);
    }
    // Set up theme system for the maintenance page.
    drupal_maintenance_theme();
    // Check existing settings.php.
    $verify = install_verify_settings();
    if ($verify) {
        // Establish a connection to the database.
        require_once DRUPAL_ROOT . '/includes/database.inc';
        db_set_active();
        // Check if Drupal is installed.
        $task = install_verify_drupal();
        if ($task == 'done') {
            install_already_done_error();
        }
    } else {
        $task = NULL;
    }
    // No profile was passed in GET, ask the user.
    if (empty($_GET['profile'])) {
        if ($profile = install_select_profile()) {
            install_goto("install.php?profile={$profile}");
        } else {
            install_no_profile_error();
        }
    }
    // Load the profile.
    require_once DRUPAL_ROOT . "/profiles/{$profile}/{$profile}.profile";
    // Locale selection
    if (!empty($_GET['locale'])) {
        $install_locale = preg_replace('/[^a-zA-Z_0-9\\-]/', '', $_GET['locale']);
    } elseif (($install_locale = install_select_locale($profile)) !== FALSE) {
        install_goto("install.php?profile={$profile}&locale={$install_locale}");
    }
    // Tasks come after the database is set up
    if (!$task) {
        global $db_url;
        if (!$verify && !empty($db_url)) {
            // Do not install over a configured settings.php.
            install_already_done_error();
        }
        // Check the installation requirements for Drupal and this profile.
        install_check_requirements($profile, $verify);
        // Verify existence of all required modules.
        $modules = drupal_verify_profile($profile, $install_locale);
        // If any error messages are set now, it means a requirement problem.
        $messages = drupal_set_message();
        if (!empty($messages['error'])) {
            install_task_list('requirements');
            drupal_set_title(st('Requirements problem'));
            print theme('install_page', '');
            exit;
        }
        // Change the settings.php information if verification failed earlier.
        // Note: will trigger a redirect if database credentials change.
        if (!$verify) {
            install_change_settings($profile, $install_locale);
        }
        // The default lock implementation uses a database table,
        // so we cannot use it for install, but we still need
        // the API functions available.
        require_once './includes/lock-install.inc';
        $conf['lock_inc'] = './includes/lock-install.inc';
        lock_init();
        // Install system.module.
        drupal_install_system();
        // Ensure that all of Drupal's standard directories have appropriate
        // .htaccess files. These directories will have already been created by
        // this point in the installer, since Drupal creates them during the
        // install_check_requirements() task. Note that we cannot create them any
        // earlier than this, since the code below relies on system.module in order
        // to work.
        file_create_htaccess(file_directory_path());
        file_create_htaccess(file_directory_temp());
        // Save the list of other modules to install for the 'profile-install'
        // task. variable_set() can be used now that system.module is installed
        // and drupal is bootstrapped.
        variable_set('install_profile_modules', array_diff($modules, array('system')));
    }
    // The database is set up, turn to further tasks.
    install_tasks($profile, $task);
}
Пример #17
0
 public function getLogDir()
 {
     require_once DRUPAL_ROOT . '/includes/file.inc';
     return file_directory_temp() . '/' . $this->getName() . '/logs';
 }
Пример #18
0
 /**
  * {@inheritdoc}
  */
 public function getDirectoryPath()
 {
     return file_directory_temp();
 }
 /**
  * {@inheritdoc}
  */
 public function debug($input, $name = NULL, $plugin_id = NULL)
 {
     $output = $this->createInstance($plugin_id)->export($input, $name) . "\n";
     // The temp directory does vary across multiple simpletest instances.
     $file = file_directory_temp() . '/drupal_debug.txt';
     if (file_put_contents($file, $output, FILE_APPEND) === FALSE && $this->hasAccessToDevelInformation()) {
         drupal_set_message(t('Devel was unable to write to %file.', ['%file' => $file]), 'error');
         return FALSE;
     }
 }
Пример #20
0
 public static function getProjectDir($project_name)
 {
     return file_directory_temp() . "/" . $project_name;
 }
Пример #21
0
 /**
  * Tests an export and import of collections.
  */
 public function testExportImportCollections()
 {
     /** @var \Drupal\Core\Config\StorageInterface $active_storage */
     $active_storage = \Drupal::service('config.storage');
     $test1_storage = $active_storage->createCollection('collection.test1');
     $test1_storage->write('config_test.create', array('foo' => 'bar'));
     $test1_storage->write('config_test.update', array('foo' => 'bar'));
     $test2_storage = $active_storage->createCollection('collection.test2');
     $test2_storage->write('config_test.another_create', array('foo' => 'bar'));
     $test2_storage->write('config_test.another_update', array('foo' => 'bar'));
     // Export the configuration.
     $this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export');
     $this->tarball = $this->drupalGetContent();
     $filename = file_directory_temp() . '/' . $this->randomName();
     file_put_contents($filename, $this->tarball);
     // Set up the active storage collections to test import.
     $test1_storage->delete('config_test.create');
     $test1_storage->write('config_test.update', array('foo' => 'baz'));
     $test1_storage->write('config_test.delete', array('foo' => 'bar'));
     $test2_storage->delete('config_test.another_create');
     $test2_storage->write('config_test.another_update', array('foo' => 'baz'));
     $test2_storage->write('config_test.another_delete', array('foo' => 'bar'));
     // Create a snapshot.
     $snapshot_storage = \Drupal::service('config.storage.snapshot');
     \Drupal::service('config.manager')->createSnapshot($active_storage, $snapshot_storage);
     // Ensure that the snapshot has the expected collection data before import.
     $test1_snapshot = $snapshot_storage->createCollection('collection.test1');
     $data = $test1_snapshot->read('config_test.delete');
     $this->assertEqual($data, array('foo' => 'bar'), 'The config_test.delete in collection.test1 exists in the snapshot storage.');
     $data = $test1_snapshot->read('config_test.update');
     $this->assertEqual($data, array('foo' => 'baz'), 'The config_test.update in collection.test1 exists in the snapshot storage.');
     $this->assertFalse($test1_snapshot->read('config_test.create'), 'The config_test.create in collection.test1 does not exist in the snapshot storage.');
     $test2_snapshot = $snapshot_storage->createCollection('collection.test2');
     $data = $test2_snapshot->read('config_test.another_delete');
     $this->assertEqual($data, array('foo' => 'bar'), 'The config_test.another_delete in collection.test2 exists in the snapshot storage.');
     $data = $test2_snapshot->read('config_test.another_update');
     $this->assertEqual($data, array('foo' => 'baz'), 'The config_test.another_update in collection.test2 exists in the snapshot storage.');
     $this->assertFalse($test2_snapshot->read('config_test.another_create'), 'The config_test.another_create in collection.test2 does not exist in the snapshot storage.');
     // Create the tar contains the expected contect for the collections.
     $tar = new ArchiveTar($filename, 'gz');
     $content_list = $tar->listContent();
     // Convert the list of files into something easy to search.
     $files = array();
     foreach ($content_list as $file) {
         $files[] = $file['filename'];
     }
     $this->assertTrue(in_array('collection/test1/config_test.create.yml', $files), 'Config export contains collection/test1/config_test.create.yml.');
     $this->assertTrue(in_array('collection/test2/config_test.another_create.yml', $files), 'Config export contains collection/test2/config_test.another_create.yml.');
     $this->assertTrue(in_array('collection/test1/config_test.update.yml', $files), 'Config export contains collection/test1/config_test.update.yml.');
     $this->assertTrue(in_array('collection/test2/config_test.another_update.yml', $files), 'Config export contains collection/test2/config_test.another_update.yml.');
     $this->assertFalse(in_array('collection/test1/config_test.delete.yml', $files), 'Config export does not contain collection/test1/config_test.delete.yml.');
     $this->assertFalse(in_array('collection/test2/config_test.another_delete.yml', $files), 'Config export does not contain collection/test2/config_test.another_delete.yml.');
     $this->drupalPostForm('admin/config/development/configuration/full/import', array('files[import_tarball]' => $filename), 'Upload');
     // Verify that there are configuration differences to import.
     $this->drupalGet('admin/config/development/configuration');
     $this->assertNoText(t('There are no configuration changes.'));
     $this->assertText(t('!collection configuration collection', array('!collection' => 'collection.test1')));
     $this->assertText(t('!collection configuration collection', array('!collection' => 'collection.test2')));
     $this->assertText('config_test.create');
     $this->assertLinkByHref('admin/config/development/configuration/sync/diff_collection/collection.test1/config_test.create');
     $this->assertText('config_test.update');
     $this->assertLinkByHref('admin/config/development/configuration/sync/diff_collection/collection.test1/config_test.update');
     $this->assertText('config_test.delete');
     $this->assertLinkByHref('admin/config/development/configuration/sync/diff_collection/collection.test1/config_test.delete');
     $this->assertText('config_test.another_create');
     $this->assertLinkByHref('admin/config/development/configuration/sync/diff_collection/collection.test2/config_test.another_create');
     $this->assertText('config_test.another_update');
     $this->assertLinkByHref('admin/config/development/configuration/sync/diff_collection/collection.test2/config_test.another_update');
     $this->assertText('config_test.another_delete');
     $this->assertLinkByHref('admin/config/development/configuration/sync/diff_collection/collection.test2/config_test.another_delete');
     $this->drupalPostForm(NULL, array(), 'Import all');
     $this->assertText(t('There are no configuration changes.'));
     // Test data in collections.
     $data = $test1_storage->read('config_test.create');
     $this->assertEqual($data, array('foo' => 'bar'), 'The config_test.create in collection.test1 has been created.');
     $data = $test1_storage->read('config_test.update');
     $this->assertEqual($data, array('foo' => 'bar'), 'The config_test.update in collection.test1 has been updated.');
     $this->assertFalse($test1_storage->read('config_test.delete'), 'The config_test.delete in collection.test1 has been deleted.');
     $data = $test2_storage->read('config_test.another_create');
     $this->assertEqual($data, array('foo' => 'bar'), 'The config_test.another_create in collection.test2 has been created.');
     $data = $test2_storage->read('config_test.another_update');
     $this->assertEqual($data, array('foo' => 'bar'), 'The config_test.another_update in collection.test2 has been updated.');
     $this->assertFalse($test2_storage->read('config_test.another_delete'), 'The config_test.another_delete in collection.test2 has been deleted.');
     // Ensure that the snapshot has been updated with the collection data.
     $snapshot_storage = \Drupal::service('config.storage.snapshot');
     $test1_snapshot = $snapshot_storage->createCollection('collection.test1');
     $data = $test1_snapshot->read('config_test.create');
     $this->assertEqual($data, array('foo' => 'bar'), 'The config_test.create in collection.test1 has been created in the snapshot storage.');
     $data = $test1_snapshot->read('config_test.update');
     $this->assertEqual($data, array('foo' => 'bar'), 'The config_test.update in collection.test1 has been updated in the snapshot storage.');
     $this->assertFalse($test1_snapshot->read('config_test.delete'), 'The config_test.delete in collection.test1 does not exist in the snapshot storage.');
     $test2_snapshot = $snapshot_storage->createCollection('collection.test2');
     $data = $test2_snapshot->read('config_test.another_create');
     $this->assertEqual($data, array('foo' => 'bar'), 'The config_test.another_create in collection.test2 has been created in the snapshot storage.');
     $data = $test2_snapshot->read('config_test.another_update');
     $this->assertEqual($data, array('foo' => 'bar'), 'The config_test.another_update in collection.test2 has been updated in the snapshot storage.');
     $this->assertFalse($test2_snapshot->read('config_test.another_delete'), 'The config_test.another_delete in collection.test2 does not exist in the snapshot storage.');
 }
    /**
     * Test variable is dumped in page.
     */
    function testDumpersOutput()
    {
        $edit = ['dumper' => 'available_test_dumper'];
        $this->drupalPostForm('admin/config/development/devel', $edit, t('Save configuration'));
        $this->assertText(t('The configuration options have been saved.'));
        $this->drupalGet('devel_dumper_test/dump');
        $elements = $this->xpath('//body/pre[contains(text(), :message)]', [':message' => 'AvailableTestDumper::dump() Test output']);
        $this->assertTrue(!empty($elements), 'Dumped message is present.');
        $this->drupalGet('devel_dumper_test/message');
        $elements = $this->xpath('//div[contains(@class, "messages")]/pre[contains(text(), :message)]', [':message' => 'AvailableTestDumper::export() Test output']);
        $this->assertTrue(!empty($elements), 'Dumped message is present.');
        $this->drupalGet('devel_dumper_test/export');
        $elements = $this->xpath('//div[@class="layout-content"]//pre[contains(text(), :message)]', [':message' => 'AvailableTestDumper::export() Test output']);
        $this->assertTrue(!empty($elements), 'Dumped message is present.');
        $this->drupalGet('devel_dumper_test/export_renderable');
        $elements = $this->xpath('//div[@class="layout-content"]//pre[contains(text(), :message)]', [':message' => 'AvailableTestDumper::exportAsRenderable() Test output']);
        $this->assertTrue(!empty($elements), 'Dumped message is present.');
        // Ensures that plugins can add libraries to the page when the
        // ::exportAsRenderable() method is used.
        $this->assertRaw('devel_dumper_test/css/devel_dumper_test.css');
        $this->assertRaw('devel_dumper_test/js/devel_dumper_test.js');
        $debug_filename = file_directory_temp() . '/drupal_debug.txt';
        $this->drupalGet('devel_dumper_test/debug');
        $file_content = file_get_contents($debug_filename);
        $expected = <<<EOF
<pre>AvailableTestDumper::export() Test output</pre>

EOF;
        $this->assertEqual($file_content, $expected, 'Dumped message is present.');
        // Ensures that the DevelDumperManager::debug() is not access checked and
        // that the dump is written in the debug file even if the user has not the
        // 'access devel information' permission.
        file_put_contents($debug_filename, '');
        $this->drupalLogout();
        $this->drupalGet('devel_dumper_test/debug');
        $file_content = file_get_contents($debug_filename);
        $expected = <<<EOF
<pre>AvailableTestDumper::export() Test output</pre>

EOF;
        $this->assertEqual($file_content, $expected, 'Dumped message is present.');
    }
Пример #23
0
/**
 * @file
 * Theme settings for the sasson
 */
function sasson_form_system_theme_settings_alter(&$form, &$form_state)
{
    global $theme_key;
    drupal_add_css(drupal_get_path('theme', 'sasson') . '/stylesheets/theme-settings.css');
    drupal_add_js(drupal_get_path('theme', 'sasson') . '/scripts/themeSettings.js');
    $select_toggle = '<br>' . l(t('select all'), '#', array('attributes' => array('class' => 'select-all'))) . ' | ' . l(t('select none'), '#', array('attributes' => array('class' => 'select-none')));
    $form['sasson_settings'] = array('#type' => 'vertical_tabs', '#weight' => -10, '#prefix' => '<h3>' . t('Theme configuration') . '</h3>');
    /**
     * Responsive Layout Settings
     */
    $form['sasson_settings']['sasson_layout'] = array('#type' => 'fieldset', '#title' => t('Responsive Layout Settings'));
    $form['sasson_settings']['sasson_layout']['sasson_responsive'] = array('#type' => 'checkbox', '#title' => t('Enable responsive layout'), '#attributes' => array('class' => array('enable-extension')), '#description' => t("Disable if you don't want your site layout to adapt to small devices, this enables both the css3 media-queries that takes care of adapting the layout and the 'viewport' meta tag that makes sure mobile devices properly display your layout."), '#default_value' => theme_get_setting('sasson_responsive'));
    $form['sasson_settings']['sasson_layout']['sasson_responsive_approach'] = array('#type' => 'radios', '#title' => t('Desktop or Mobile first'), '#options' => array('desktop_first' => t('Desktop first'), 'mobile_first' => t('Mobile first')), '#description' => t('Select they way your responsive layout should be constructed. desktop-first means we start with desktop size page and reduce accordingly, mobile-first means we start with a very simple layout and build on top of that.'), '#default_value' => theme_get_setting('sasson_responsive_approach'));
    $form['sasson_settings']['sasson_layout']['media_break_points'] = array('#markup' => '<strong>' . t('Media queries break-point are being set via <code>!settings</code>. Copy it to your sub-theme and set your own values.', array('!settings' => l('_settings.scss', 'http://drupalcode.org/project/sasson.git/blob/refs/heads/7.x-3.x:/sass/_settings.scss', array('attributes' => array('target' => '_blank'))))) . '</strong>');
    $form['sasson_settings']['sasson_layout']['responsive_menus'] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Responsive menus'));
    $form['sasson_settings']['sasson_layout']['responsive_menus']['sasson_responsive_menus_width'] = array('#type' => 'textfield', '#size' => 10, '#title' => t('Responsive menus page width'), '#description' => t("Set the width in which the selected menus turn into a select menu, or 0 to disable."), '#default_value' => theme_get_setting('sasson_responsive_menus_width'));
    $form['sasson_settings']['sasson_layout']['responsive_menus']['sasson_responsive_menus_selectors'] = array('#type' => 'textfield', '#title' => t('Responsive menus selectors'), '#description' => t("Enter some CSS selectors for the menus you want to alter."), '#default_value' => theme_get_setting('sasson_responsive_menus_selectors'));
    $form['sasson_settings']['sasson_layout']['responsive_menus']['sasson_responsive_menus_autohide'] = array('#type' => 'checkbox', '#title' => t('Auto-hide the standard menu'), '#default_value' => theme_get_setting('sasson_responsive_menus_autohide'));
    /**
     * CSS settings
     */
    $form['sasson_settings']['sasson_css'] = array('#type' => 'fieldset', '#title' => t('CSS settings'));
    $form['sasson_settings']['sasson_css']['sasson_reset'] = array('#type' => 'fieldset', '#title' => t('CSS Reset VS Normalize'));
    $form['sasson_settings']['sasson_css']['sasson_reset']['sasson_cssreset'] = array('#type' => 'radios', '#options' => array('normalize' => t('Use !normalize from !h5bp.', array('!normalize' => l('normalize.css', 'http://necolas.github.com/normalize.css/', array('attributes' => array('target' => '_blank'))), '!h5bp' => l('HTML5 Boilerplate', 'http://html5boilerplate.com/', array('attributes' => array('target' => '_blank'))))), 'reset' => t("Use !meyer's CSS reset.", array('!meyer' => l('Eric Meyer', 'http://meyerweb.com/eric/tools/css/reset/', array('attributes' => array('target' => '_blank'))))), 'none' => t("None")), '#description' => t('Normalize.css makes browsers render all elements more consistently and in line with modern standards, while preserving useful defaults.<br>
      Reset.css will reset css values (e.g. set 0) to reduce browser inconsistencies in things like default line heights, margins and font sizes.'), '#default_value' => theme_get_setting('sasson_cssreset'));
    $form['sasson_settings']['sasson_css']['sasson_forms'] = array('#type' => 'fieldset', '#title' => t('Forms styling'));
    $form['sasson_settings']['sasson_css']['sasson_forms']['sasson_formalize'] = array('#type' => 'checkbox', '#title' => t("Use !formalize to reset your forms.", array('!formalize' => l('Formalize', 'http://formalize.me/', array('attributes' => array('target' => '_blank'))))), '#description' => t('Apply consistent and cross-browser styles to all forms.'), '#default_value' => theme_get_setting('sasson_formalize'));
    // Disable CSS
    require_once drupal_get_path('theme', 'sasson') . '/includes/assets.inc';
    $form['sasson_settings']['sasson_css']['sasson_disablecss'] = array('#type' => 'fieldset', '#title' => t('Disable CSS files'));
    $form['sasson_settings']['sasson_css']['sasson_disablecss']['sasson_disable_css'] = array('#type' => 'checkbox', '#title' => t("Enable this extension."), '#attributes' => array('class' => array('enable-extension')), '#description' => t('Disable all CSS files included by core and contrib modules or choose specific CSS files to disable.'), '#default_value' => theme_get_setting('sasson_disable_css'));
    $form['sasson_settings']['sasson_css']['sasson_disablecss']['modules'] = array('#type' => 'fieldset', '#title' => t('Per module'), '#description' => t('Disable all CSS files from selected modules.') . $select_toggle, '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['sasson_settings']['sasson_css']['sasson_disablecss']['modules']['sasson_disable_css_modules'] = array('#type' => 'checkboxes', '#title' => t('Modules'), '#options' => sasson_get_modules_list(), '#default_value' => theme_get_setting('sasson_disable_css_modules') ? theme_get_setting('sasson_disable_css_modules') : array());
    $form['sasson_settings']['sasson_css']['sasson_disablecss']['files'] = array('#type' => 'fieldset', '#title' => t('Specific CSS files'), '#description' => t('Disable specific CSS files from core and contrib modules.') . $select_toggle, '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['sasson_settings']['sasson_css']['sasson_disablecss']['files']['sasson_disable_css_files'] = array('#type' => 'checkboxes', '#title' => t('Disable specific css files.'), '#options' => sasson_get_assets_list(), '#default_value' => theme_get_setting('sasson_disable_css_files') ? theme_get_setting('sasson_disable_css_files') : array());
    /**
     * JavaScript Settings
     */
    $form['sasson_settings']['sasson_js'] = array('#type' => 'fieldset', '#title' => t('JavaScript Settings'));
    $form['sasson_settings']['sasson_js']['sasson_js_footer_wrapper'] = array('#type' => 'fieldset', '#title' => t('Move JavaScript to footer'));
    $form['sasson_settings']['sasson_js']['sasson_js_footer_wrapper']['sasson_js_footer'] = array('#type' => 'checkbox', '#title' => t('Move all scripts to the footer.'), '#description' => t('Yahoo! Exceptional Performance team recommends <a href="http://developer.yahoo.com/performance/rules.html#js_bottom">placing scripts at the bottom of your page</a> because of the way browsers download components.') . '<br>' . t('This will move all your scripts to the bottom of your page. You can still force a script to go in the <code>head</code> by setting <code>"force_header" => TRUE</code> in your !drupal_add_js options array.', array('!drupal_add_js' => l('drupal_add_js', 'http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_js', array('attributes' => array('target' => '_blank'))))), '#default_value' => theme_get_setting('sasson_js_footer'));
    $form['sasson_settings']['sasson_js']['sasson_latestjs'] = array('#type' => 'fieldset', '#title' => t('Latest jQuery from Google'));
    $form['sasson_settings']['sasson_js']['sasson_latestjs']['sasson_latest_jquery'] = array('#type' => 'checkbox', '#title' => t('Replace core\'s jQuery with latest version from Google\'s CDN.'), '#default_value' => theme_get_setting('sasson_latest_jquery'), '#description' => t('<strong>Note:</strong> this might break scripts that depend on deprecated jQuery features.'));
    // Disable JS
    $form['sasson_settings']['sasson_js']['sasson_disablejs'] = array('#type' => 'fieldset', '#title' => t('Disable JS files'));
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['sasson_disable_js'] = array('#type' => 'checkbox', '#title' => t("Enable this extension."), '#attributes' => array('class' => array('enable-extension')), '#description' => t('Disable all JS files included by core and contrib modules or choose specific JS files to disable.'), '#default_value' => theme_get_setting('sasson_disable_js'));
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['modules'] = array('#type' => 'fieldset', '#title' => t('Per module'), '#description' => t('Disable all JS files from selected modules.') . $select_toggle, '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['modules']['sasson_disable_js_modules'] = array('#type' => 'checkboxes', '#title' => t('Modules'), '#options' => sasson_get_modules_list(), '#default_value' => theme_get_setting('sasson_disable_js_modules') ? theme_get_setting('sasson_disable_js_modules') : array());
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['files'] = array('#type' => 'fieldset', '#title' => t('Specific JS files'), '#description' => t('Disable specific JS files from core and contrib modules.') . $select_toggle, '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['files']['sasson_disable_js_files'] = array('#type' => 'checkboxes', '#title' => t('Disable specific JS files.'), '#options' => sasson_get_assets_list('js'), '#default_value' => theme_get_setting('sasson_disable_js_files') ? theme_get_setting('sasson_disable_js_files') : array());
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['jquery'] = array('#type' => 'fieldset', '#title' => t('Core jQuery & jQuery UI'), '#description' => t('Disable specific jQuery & jQuery UI files from core.') . $select_toggle, '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['jquery']['sasson_disable_jquery_files'] = array('#type' => 'checkboxes', '#title' => t('Disable core jQuery & jQuery UI files.'), '#options' => sasson_get_assets_list('js', 'jquery'), '#default_value' => theme_get_setting('sasson_disable_jquery_files') ? theme_get_setting('sasson_disable_jquery_files') : array());
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['sasson_js'] = array('#type' => 'fieldset', '#title' => t('Sasson\'s JS'));
    $form['sasson_settings']['sasson_js']['sasson_disablejs']['sasson_js']['sasson_disable_sasson_js'] = array('#type' => 'checkbox', '#title' => t('Disable all JS from Sasson.'), '#description' => t('<strong>Note:</strong> this will break Sasson\'s scripts like the file-watcher and mobile menus if they are enabled, be warned.'), '#default_value' => theme_get_setting('sasson_disable_sasson_js'));
    /**
     * HTML5 IE support
     */
    $form['sasson_settings']['sasson_html5'] = array('#type' => 'fieldset', '#title' => t('HTML5 IE support'));
    $form['sasson_settings']['sasson_html5']['sasson_force_ie'] = array('#type' => 'checkbox', '#title' => t('Force latest IE rendering engine (even in intranet) & Chrome Frame'), '#default_value' => theme_get_setting('sasson_force_ie'));
    $form['sasson_settings']['sasson_html5']['sasson_html5shiv'] = array('#type' => 'checkbox', '#title' => t('Enable HTML5 elements in IE'), '#description' => t('Makes IE understand HTML5 elements via <a href="!shivlink">HTML5 shiv</a>. disable if you use a different method.', array('!shivlink' => 'http://code.google.com/p/html5shiv/')), '#default_value' => theme_get_setting('sasson_html5shiv'));
    $form['sasson_settings']['sasson_html5']['sasson_ie_comments'] = array('#type' => 'checkbox', '#title' => t('Add IE specific classes'), '#description' => t('This will add conditional classes to the html tag for IE specific styling. see this <a href="!post">post</a> for more info.', array('!post' => 'http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/')), '#default_value' => theme_get_setting('sasson_ie_comments'));
    $form['sasson_settings']['sasson_html5']['sasson_prompt_cf'] = array('#type' => 'select', '#title' => t('Prompt old IE users to update'), '#default_value' => theme_get_setting('sasson_prompt_cf'), '#options' => drupal_map_assoc(array('Disabled', 'IE 6', 'IE 7', 'IE 8', 'IE 9')), '#description' => t('Set the latest IE version you would like the prompt box to show on or disable if you want to support old IEs.'));
    /**
     * Fonts
     */
    $form['sasson_settings']['sasson_fonts'] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t("\n      Set a custom font to be used across the site. you may override typography settings in you sub-theme's css/sass/scss files.<br>\n      <strong>Note:</strong> Only fonts from !webfont are supported at the moment, if this is not enough you should check out !fontyourface module.", array('!webfont' => l('google web fonts', 'http://www.google.com/webfonts', array('attributes' => array('target' => '_blank'))), '!fontyourface' => l('@font-your-face', 'http://drupal.org/project/fontyourface', array('attributes' => array('target' => '_blank'))))), '#title' => t('Fonts'));
    $form['sasson_settings']['sasson_fonts']['sasson_font'] = array('#type' => 'textfield', '#title' => t('Font name'), '#description' => t("Enter the font name from Google web fonts."), '#default_value' => theme_get_setting('sasson_font'));
    $form['sasson_settings']['sasson_fonts']['sasson_font_fallback'] = array('#type' => 'textfield', '#title' => t('Font fallback'), '#description' => t("Enter the font names you would like as a fallback in a comma separated list. e.g. <code>'Times New Roman', Times, serif</code>."), '#default_value' => theme_get_setting('sasson_font_fallback'));
    $form['sasson_settings']['sasson_fonts']['sasson_font_selectors'] = array('#type' => 'textfield', '#title' => t('CSS selectors'), '#description' => t("Enter some CSS selectors for the fonts to apply to. if none is provided it will default to a <code>.sasson-font-face</code> class"), '#default_value' => theme_get_setting('sasson_font_selectors'));
    /**
     * Development Settings
     */
    $form['sasson_settings']['sasson_development'] = array('#type' => 'fieldset', '#title' => t('Development'));
    $form['sasson_settings']['sasson_development']['sasson_watch'] = array('#type' => 'fieldset', '#title' => t('File Watcher'));
    $form['sasson_settings']['sasson_development']['sasson_watch']['sasson_watcher'] = array('#type' => 'checkbox', '#title' => t('Watch for file changes and automatically refresh the browser.'), '#attributes' => array('class' => array('enable-extension')), '#description' => t('With this feature on, you may enter a list of URLs for files to be watched, whenever a file is changed, your browser will automagically update itself.<br><strong>Turn this off when not actively developing.</strong>'), '#default_value' => theme_get_setting('sasson_watcher'));
    $form['sasson_settings']['sasson_development']['sasson_watch']['sasson_watch_file'] = array('#type' => 'textarea', '#title' => t('Files to watch'), '#description' => t('Enter the internal path of the files to be watched. one file per line. no leading slash.<br> e.g. sites/all/themes/sasson/stylesheets/sasson.scss<br>Lines starting with a semicolon (;) will be ignored.<br><strong>Keep this list short !</strong> Watch only the files you currently work on.'), '#rows' => 3, '#default_value' => theme_get_setting('sasson_watch_file'));
    $form['sasson_settings']['sasson_development']['sasson_grid'] = array('#type' => 'fieldset', '#title' => t('Grid background'));
    $form['sasson_settings']['sasson_development']['sasson_grid']['sasson_show_grid'] = array('#type' => 'checkbox', '#title' => t('Show grid background layer.'), '#description' => t('Display a visible background grid, for easier elements positioning'), '#default_value' => theme_get_setting('sasson_show_grid'));
    $form['sasson_settings']['sasson_development']['sasson_overlay'] = array('#type' => 'fieldset', '#title' => t('Design Overlay'));
    $form['sasson_settings']['sasson_development']['sasson_overlay']['sasson_overlay'] = array('#type' => 'checkbox', '#title' => t('Enable overlay image'), '#attributes' => array('class' => array('enable-extension')), '#description' => t('With this feature on, you may upload an image that will be place as a draggable overlay image over your HTML for easy visual comparison. you may also set different overlay opacity.'), '#default_value' => theme_get_setting('sasson_overlay'));
    $form['sasson_settings']['sasson_development']['sasson_overlay']['sasson_overlay_file'] = array('#type' => 'managed_file', '#title' => t('Upload overlay image'), '#upload_location' => file_default_scheme() . '://sasson/overlay/', '#default_value' => theme_get_setting('sasson_overlay_file'), '#upload_validators' => array('file_validate_extensions' => array('gif png jpg jpeg')));
    $form['sasson_settings']['sasson_development']['sasson_overlay']['sasson_overlay_opacity'] = array('#type' => 'select', '#title' => t('Overlay opacity'), '#default_value' => theme_get_setting('sasson_overlay_opacity'), '#options' => drupal_map_assoc(array('0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1')));
    $form['sasson_settings']['sasson_development']['sasson_mail_dev'] = array('#type' => 'fieldset', '#title' => t('HTML Mail debugger'), '#description' => t('Useful tools for HTML mail development.') . $select_toggle);
    $debug_file = DRUPAL_ROOT . '/' . file_directory_temp() . '/mail_debug/mail_debug.html';
    $form['sasson_settings']['sasson_development']['sasson_mail_dev']['sasson_mail_to_file'] = array('#type' => 'checkbox', '#title' => t('Write mail messages to file'), '#description' => t('All mail messages will be written to <code>!file</code>', array('!file' => $debug_file)), '#default_value' => theme_get_setting('sasson_mail_to_file'));
    $form['sasson_settings']['sasson_development']['sasson_mail_dev']['sasson_mail_to_log'] = array('#type' => 'checkbox', '#title' => t('Write mail messages to log'), '#description' => t('All mail messages will be logged to the !db.', array('!db' => l('database', 'admin/reports/dblog'))), '#default_value' => theme_get_setting('sasson_mail_to_log'));
    $form['sasson_settings']['sasson_development']['sasson_mail_dev']['sasson_mail_devel'] = array('#type' => 'checkbox', '#title' => t('Display development messages'), '#description' => t('Show a development message after mail is sent (requires devel module)'), '#default_value' => theme_get_setting('sasson_mail_devel'));
    $form['sasson_settings']['sasson_development']['sasson_mail_dev']['sasson_mail_prevent'] = array('#type' => 'checkbox', '#title' => t('Prevent mail from being sent'), '#description' => t('Prevent outgoing mail messages from being sent while developing.'), '#default_value' => theme_get_setting('sasson_mail_prevent'));
    /**
     * General Settings
     */
    $form['sasson_settings']['sasson_general'] = array('#type' => 'fieldset', '#title' => t('General'));
    $admin_theme = variable_get('admin_theme', 0);
    if (!empty($admin_theme) && $admin_theme != $theme_key) {
        $form['sasson_settings']['sasson_general']['theme_settings'] = $form['theme_settings'];
        $form['sasson_settings']['sasson_general']['logo'] = $form['logo'];
        $form['sasson_settings']['sasson_general']['favicon'] = $form['favicon'];
        unset($form['theme_settings']);
        unset($form['logo']);
        unset($form['favicon']);
    } else {
        $form['theme_settings']['#collapsible'] = TRUE;
        $form['theme_settings']['#collapsed'] = TRUE;
        $form['logo']['#collapsible'] = TRUE;
        $form['logo']['#collapsed'] = TRUE;
        $form['favicon']['#collapsible'] = TRUE;
        $form['favicon']['#collapsed'] = TRUE;
    }
    $form['sasson_settings']['sasson_general']['sasson_breadcrumb'] = array('#type' => 'fieldset', '#title' => t('Breadcrumbs'));
    $form['sasson_settings']['sasson_general']['sasson_breadcrumb']['sasson_breadcrumb_hideonlyfront'] = array('#type' => 'checkbox', '#title' => t('Hide the breadcrumb if the breadcrumb only contains the link to the front page.'), '#default_value' => theme_get_setting('sasson_breadcrumb_hideonlyfront'));
    $form['sasson_settings']['sasson_general']['sasson_breadcrumb']['sasson_breadcrumb_showtitle'] = array('#type' => 'checkbox', '#title' => t('Show page title on breadcrumb.'), '#default_value' => theme_get_setting('sasson_breadcrumb_showtitle'));
    $form['sasson_settings']['sasson_general']['sasson_breadcrumb']['sasson_breadcrumb_separator'] = array('#type' => 'textfield', '#title' => t('Breadcrumb separator'), '#default_value' => theme_get_setting('sasson_breadcrumb_separator'));
    $form['sasson_settings']['sasson_general']['sasson_rss'] = array('#type' => 'fieldset', '#title' => t('RSS'));
    $form['sasson_settings']['sasson_general']['sasson_rss']['sasson_feed_icons'] = array('#type' => 'checkbox', '#title' => t('Display Feed Icons'), '#default_value' => theme_get_setting('sasson_feed_icons'));
}
Пример #24
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $directory = $input->getArgument('directory');
     if (!$directory) {
         $config = $this->getConfigFactory()->get('system.file');
         $directory = $config->get('path.temporary') ?: file_directory_temp();
         $directory .= '/' . CONFIG_STAGING_DIRECTORY;
     }
     if (!is_dir($directory)) {
         mkdir($directory, 0777, true);
     }
     $config_name = $input->getArgument('config-name');
     $config_export_file = $directory . '/' . $config_name . '.yml';
     file_unmanaged_delete($config_export_file);
     $config = $this->getConfigFactory()->getEditable($config_name);
     if ($config) {
         $yaml = Yaml::encode($config->getRawData());
         // Save release file
         file_put_contents($config_export_file, $yaml);
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.config.export.single.messages.export'), $config_export_file) . '</info>');
     } else {
         $output->writeln('[+] <error>' . $this->trans('commands.config.export.single.messages.config-not-found') . '</error>');
     }
 }
Пример #25
0
 /**
  * @covers \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationWrite
  */
 public function testExportWrite()
 {
     // Set a fake drupal root, so the testbot can also write into it.
     vfsStream::setup('drupal');
     \Drupal::getContainer()->set('app.root', 'vfs://drupal');
     $this->featuresManager->setRoot('vfs://drupal');
     $package = $this->featuresManager->getPackage(self::PACKAGE_NAME);
     // Find out where package will be exported
     list($full_name, $path) = $this->featuresManager->getExportInfo($package, $this->assigner->getBundle());
     $path = 'vfs://drupal/' . $path . '/' . $full_name;
     if (file_exists($path)) {
         file_unmanaged_delete_recursive($path);
     }
     $this->assertFalse(file_exists($path), 'Package directory already exists.');
     $this->generator->generatePackages('write', $this->assigner->getBundle(), [self::PACKAGE_NAME]);
     $info_file_uri = $path . '/' . self::PACKAGE_NAME . '.info.yml';
     $this->assertTrue(file_exists($path), 'Package directory was not generated.');
     $this->assertTrue(file_exists($info_file_uri), 'Package info.yml not generated.');
     $this->assertTrue(file_exists($path . '/config/install'), 'Package config/install not generated.');
     $this->assertTrue(file_exists($path . '/config/install/system.site.yml'), 'Config.yml not exported.');
     $expected_info = ["name" => "My test package", "type" => "module", "core" => "8.x"];
     $info = Yaml::decode(file_get_contents($info_file_uri));
     $this->assertEquals($expected_info, $info, 'Incorrect info file generated');
     // Now, add stuff to the feature and re-export to ensure it is preserved
     // Add a dependency to the package itself to see that it gets exported.
     $package->setDependencies(['user']);
     $this->featuresManager->setPackage($package);
     // Add dependency and custom key to the info file to simulate manual edit.
     $info['dependencies'] = ['node'];
     $info['mykey'] = "test value";
     $info_contents = Yaml::encode($info);
     file_put_contents($info_file_uri, $info_contents);
     // Add an extra file that should be retained.
     $css_file = $path . '/' . self::PACKAGE_NAME . '.css';
     $file_contents = "This is a dummy file";
     file_put_contents($css_file, $file_contents);
     // Add a config file that should be removed since it's not part of the
     // feature.
     $config_file = $path . '/config/install/node.type.mytype.yml';
     file_put_contents($config_file, $file_contents);
     $this->generator->generatePackages('write', $this->assigner->getBundle(), [self::PACKAGE_NAME]);
     $this->assertTrue(file_exists($info_file_uri), 'Package info.yml not generated.');
     $expected_info = ["name" => "My test package", "type" => "module", "core" => "8.x", "dependencies" => ["node", "user"], "mykey" => "test value"];
     $info = Yaml::decode(file_get_contents($info_file_uri));
     $this->assertEquals($expected_info, $info, 'Incorrect info file generated');
     $this->assertTrue(file_exists($css_file), 'Extra file was not retained.');
     $this->assertFalse(file_exists($config_file), 'Config directory was not cleaned.');
     $this->assertEquals($file_contents, file_get_contents($css_file), 'Extra file contents not retained');
     // Next, test that generating an Archive picks up the extra files.
     $filename = file_directory_temp() . '/' . self::PACKAGE_NAME . '.tar.gz';
     if (file_exists($filename)) {
         unlink($filename);
     }
     $this->assertFalse(file_exists($filename), 'Archive file already exists.');
     $this->generator->generatePackages('archive', $this->assigner->getBundle(), [self::PACKAGE_NAME]);
     $this->assertTrue(file_exists($filename), 'Archive file was not generated.');
     $archive = new ArchiveTar($filename);
     $files = $archive->listContent();
     $this->assertEquals(4, count($files));
     $this->assertEquals(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.info.yml', $files[0]['filename']);
     $this->assertEquals(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.features.yml', $files[1]['filename']);
     $this->assertEquals(self::PACKAGE_NAME . '/config/install/system.site.yml', $files[2]['filename']);
     $this->assertEquals(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.css', $files[3]['filename']);
     $expected_info = ["name" => "My test package", "type" => "module", "core" => "8.x", "dependencies" => ["node", "user"], "mykey" => "test value"];
     $info = Yaml::decode($archive->extractInString(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.info.yml'));
     $this->assertEquals($expected_info, $info, 'Incorrect info file generated');
     $this->assertEquals($file_contents, $archive->extractInString(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.css'), 'Extra file contents not retained');
 }
Пример #26
0
/**
 * The Drupal installation happens in a series of steps. We begin by verifying
 * that the current environment meets our minimum requirements. We then go
 * on to verify that settings.php is properly configured. From there we
 * connect to the configured database and verify that it meets our minimum
 * requirements. Finally we can allow the user to select an installation
 * profile and complete the installation process.
 *
 * @param $phase
 *   The installation phase we should proceed to.
 */
function install_main()
{
    require_once './includes/bootstrap.inc';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
    // This must go after drupal_bootstrap(), which unsets globals!
    global $profile, $install_locale, $conf;
    require_once './modules/system/system.install';
    require_once './includes/file.inc';
    // Ensure correct page headers are sent (e.g. caching)
    drupal_page_header();
    // Set up $language, so t() caller functions will still work.
    drupal_init_language();
    // Load module basics (needed for hook invokes).
    include_once './includes/module.inc';
    $module_list['system']['filename'] = 'modules/system/system.module';
    $module_list['filter']['filename'] = 'modules/filter/filter.module';
    module_list(TRUE, FALSE, FALSE, $module_list);
    drupal_load('module', 'system');
    drupal_load('module', 'filter');
    // Install profile chosen, set the global immediately.
    // This needs to be done before the theme cache gets
    // initialized in drupal_maintenance_theme().
    if (!empty($_GET['profile'])) {
        $profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']);
    }
    // Set up theme system for the maintenance page.
    drupal_maintenance_theme();
    // Check existing settings.php.
    $verify = install_verify_settings();
    if ($verify) {
        // Since we have a database connection, we use the normal cache system.
        // This is important, as the installer calls into the Drupal system for
        // the clean URL checks, so we should maintain the cache properly.
        require_once './includes/cache.inc';
        $conf['cache_inc'] = './includes/cache.inc';
        // Establish a connection to the database.
        require_once './includes/database.inc';
        db_set_active();
        // Check if Drupal is installed.
        $task = install_verify_drupal();
        if ($task == 'done') {
            install_already_done_error();
        }
    } else {
        // Since no persistent storage is available yet, and functions that check
        // for cached data will fail, we temporarily replace the normal cache
        // system with a stubbed-out version that short-circuits the actual
        // caching process and avoids any errors.
        require_once './includes/cache-install.inc';
        $conf['cache_inc'] = './includes/cache-install.inc';
        $task = NULL;
    }
    // No profile was passed in GET, ask the user.
    if (empty($_GET['profile'])) {
        if ($profile = install_select_profile()) {
            install_goto("install.php?profile={$profile}");
        } else {
            install_no_profile_error();
        }
    }
    // Load the profile.
    require_once "./profiles/{$profile}/{$profile}.profile";
    // Locale selection
    if (!empty($_GET['locale'])) {
        $install_locale = preg_replace('/[^a-zA-Z_0-9\\-]/', '', $_GET['locale']);
    } elseif (($install_locale = install_select_locale($profile)) !== FALSE) {
        install_goto("install.php?profile={$profile}&locale={$install_locale}");
    }
    // Tasks come after the database is set up
    if (!$task) {
        global $db_url;
        if (!$verify && !empty($db_url)) {
            // Do not install over a configured settings.php.
            install_already_done_error();
        }
        // Check the installation requirements for Drupal and this profile.
        install_check_requirements($profile, $verify);
        // Verify existence of all required modules.
        $modules = drupal_verify_profile($profile, $install_locale);
        // If any error messages are set now, it means a requirement problem.
        $messages = drupal_set_message();
        if (!empty($messages['error'])) {
            install_task_list('requirements');
            drupal_set_title(st('Requirements problem'));
            print theme('install_page', '');
            exit;
        }
        // Change the settings.php information if verification failed earlier.
        // Note: will trigger a redirect if database credentials change.
        if (!$verify) {
            install_change_settings($profile, $install_locale);
        }
        // The default lock implementation uses a database table,
        // so we cannot use it for install, but we still need
        // the API functions available.
        require_once './includes/lock-install.inc';
        $conf['lock_inc'] = './includes/lock-install.inc';
        lock_init();
        // Install system.module.
        drupal_install_system();
        // Ensure that all of Drupal's standard directories have appropriate
        // .htaccess files. These directories will have already been created by
        // this point in the installer, since Drupal creates them during the
        // install_check_requirements() task. Note that we cannot create them any
        // earlier than this, since the code below relies on system.module in order
        // to work.
        file_create_htaccess(file_directory_path());
        file_create_htaccess(file_directory_temp());
        // Save the list of other modules to install for the 'profile-install'
        // task. variable_set() can be used now that system.module is installed
        // and drupal is bootstrapped.
        variable_set('install_profile_modules', array_diff($modules, array('system')));
    }
    // The database is set up, turn to further tasks.
    install_tasks($profile, $task);
}
Пример #27
0
 /**
  * Ensure that the file_directory_temp() function always returns a value.
  */
 function testFileDirectoryTemp()
 {
     // Start with an empty variable to ensure we have a clean slate.
     $config = $this->config('system.file');
     $config->set('path.temporary', '')->save();
     $tmp_directory = file_directory_temp();
     $this->assertEqual(empty($tmp_directory), FALSE, 'file_directory_temp() returned a non-empty value.');
     $this->assertEqual($config->get('path.temporary'), $tmp_directory);
 }
Пример #28
0
 /**
  * {@inheritdoc}
  */
 public static function migrateDumpAlter(KernelTestBase $test)
 {
     // Creates a random filename and updates the source database.
     $random = new Random();
     $temp_directory = file_directory_temp();
     file_prepare_directory($temp_directory, FILE_CREATE_DIRECTORY);
     static::$tempFilename = $test->getDatabasePrefix() . $random->name() . '.jpg';
     $file_path = $temp_directory . '/' . static::$tempFilename;
     file_put_contents($file_path, '');
     $db = Database::getConnection('default', 'migrate');
     $db->update('files')->condition('fid', 6)->fields(array('filename' => static::$tempFilename, 'filepath' => $file_path))->execute();
     $file = (array) $db->select('files')->fields('files')->condition('fid', 5)->execute()->fetchObject();
     unset($file['fid']);
     $db->insert('files')->fields($file)->execute();
     return static::$tempFilename;
 }
Пример #29
0
 /**
  * @param ldap entry array $ldap_entry
  *
  * @return drupal file object image user's thumbnail or FALSE if none present or ERROR happens.
  */
 public function userPictureFromLdapEntry($ldap_entry, $drupal_username = FALSE)
 {
     if ($ldap_entry && $this->picture_attr) {
         //Check if ldap entry has been provisioned.
         $thumb = isset($ldap_entry[$this->picture_attr][0]) ? $ldap_entry[$this->picture_attr][0] : FALSE;
         if (!$thumb) {
             return FALSE;
         }
         //Create md5 check.
         $md5thumb = md5($thumb);
         /**
          * If existing account already has picture check if it has changed if so remove old file and create the new one
          * If picture is not set but account has md5 something is wrong exit.
          */
         if ($drupal_username && ($account = user_load_by_name($drupal_username))) {
             if ($account->uid == 0 || $account->uid == 1) {
                 return FALSE;
             }
             if (isset($account->picture)) {
                 // Check if image has changed
                 if (isset($account->data['ldap_user']['init']['thumb5md']) && $md5thumb === $account->data['ldap_user']['init']['thumb5md']) {
                     //No change return same image
                     return $account->picture;
                 } else {
                     //Image is different check wether is obj/str and remove fileobject
                     if (is_object($account->picture)) {
                         file_delete($account->picture, TRUE);
                     } elseif (is_string($account->picture)) {
                         $file = file_load(intval($account->picture));
                         file_delete($file, TRUE);
                     }
                 }
             } elseif (isset($account->data['ldap_user']['init']['thumb5md'])) {
                 watchdog('ldap_server', "Some error happened during thumbnailPhoto sync");
                 return FALSE;
             }
         }
         //Create tmp file to get image format.
         $filename = uniqid();
         $fileuri = file_directory_temp() . '/' . $filename;
         $size = file_put_contents($fileuri, $thumb);
         $info = image_get_info($fileuri);
         unlink($fileuri);
         // create file object
         $file = file_save_data($thumb, 'public://' . variable_get('user_picture_path') . '/' . $filename . '.' . $info['extension']);
         $file->md5Sum = $md5thumb;
         // standard Drupal validators for user pictures
         $validators = array('file_validate_is_image' => array(), 'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')), 'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024));
         $errors = file_validate($file, $validators);
         if (empty($errors)) {
             return $file;
         } else {
             foreach ($errors as $err => $err_val) {
                 watchdog('ldap_server', "Error storing picture: %{$err}", "%{$err_val}", WATCHDOG_ERROR);
             }
             return FALSE;
         }
     }
 }
Пример #30
0
 /**
  * Retrieve a copy of the contents of a given file item in the
  * repository.
  *
  * (You won't get the original because repositories can often be
  * remote.)
  *
  * The caller should make sure to delete the file when it's not needed
  * anymore. That requirement might change in the future though.
  *
  * This function is optional for VCS backends to implement, be sure to
  * check the return to NULL.
  *
  * @return
  *   The local path of the created copy, if successful.
  *   NULL is returned if the given item is not under version control,
  *   or was not under version control at the time of the given
  *   revision.
  */
 public function exportFile()
 {
     if (!$this->isFile()) {
         return NULL;
     }
     $filename = basename($file_item['path']);
     $destination = file_directory_temp() . '/versioncontrol-' . mt_rand() . '-' . $filename;
     if ($this instanceof VersioncontrolItemExportFile) {
         $success = $this->_exportFile($destination);
     } else {
         return NULL;
     }
     if ($success) {
         return $destination;
     }
     @unlink($destination);
     return NULL;
 }