예제 #1
0
 /**
  * Registers Twig services.
  *
  * This method is public and static so that it can be reused in the installer.
  */
 public static function registerTwig(ContainerBuilder $container)
 {
     $container->register('twig.loader.filesystem', 'Twig_Loader_Filesystem')->addArgument(DRUPAL_ROOT);
     $container->setAlias('twig.loader', 'twig.loader.filesystem');
     $twig_extension = new Definition('Drupal\\Core\\Template\\TwigExtension');
     $twig_extension->addMethodCall('setGenerators', array(new Reference('url_generator')));
     $container->register('twig', 'Drupal\\Core\\Template\\TwigEnvironment')->addArgument(new Reference('twig.loader'))->addArgument(array('cache' => drupal_installation_attempted() ? FALSE : Settings::get('twig_cache', TRUE), 'autoescape' => TRUE, 'debug' => Settings::get('twig_debug', FALSE), 'auto_reload' => Settings::get('twig_auto_reload', NULL)))->addArgument(new Reference('module_handler'))->addArgument(new Reference('theme_handler'))->addMethodCall('addExtension', array($twig_extension))->addMethodCall('addExtension', array(new Definition('Twig_Extension_Debug')))->addTag('service_collector', array('tag' => 'twig.extension', 'call' => 'addExtension'));
 }
예제 #2
0
 public function redirectToInstall()
 {
     // Redirect the user to the installation script if Drupal has not been
     // installed yet (i.e., if no $databases array has been defined in the
     // settings.php file) and we are not already installing.
     if (empty($GLOBALS['databases']) && !drupal_installation_attempted()) {
         include_once DRUPAL_ROOT . '/includes/install.inc';
         install_goto('install.php');
     }
 }
예제 #3
0
파일: template.php 프로젝트: rujiali/govCMS
/**
 * Implements hook_preprocess_maintenance_page().
 */
function govcms_zen_preprocess_maintenance_page(&$variables)
{
    $t_function = get_t();
    if (drupal_installation_attempted()) {
        $variables['logo'] = base_path() . drupal_get_path('theme', 'govcms_zen') . '/logo.png';
        // Override the site name, which will be "Drupal".
        // @todo: Dynamically rename "govCMS" using $conf.
        $variables['site_name'] = $t_function('Install govCMS');
        // @todo: Use this to style the installer appropriately.
        $variables['classes_array'][] = 'installer';
    } else {
        if (empty($variables['content'])) {
            $variables['content'] = $t_function('This web site is currently undergoing some maintenance and is unavailable.');
        }
    }
}
 /**
  * Constructs ChainedFastBackendFactory object.
  *
  * @param \Drupal\Core\Site\Settings|null $settings
  *   (optional) The settings object.
  * @param string|null $consistent_service_name
  *   (optional) The service name of the consistent backend factory. Defaults
  *   to:
  *   - $settings->get('cache')['default'] (if specified)
  *   - 'cache.backend.database' (if the above isn't specified)
  * @param string|null $fast_service_name
  *   (optional) The service name of the fast backend factory. Defaults to:
  *   - 'cache.backend.apcu' (if the PHP process has APCu enabled)
  *   - NULL (if the PHP process doesn't have APCu enabled)
  */
 public function __construct(Settings $settings = NULL, $consistent_service_name = NULL, $fast_service_name = NULL)
 {
     // Default the consistent backend to the site's default backend.
     if (!isset($consistent_service_name)) {
         $cache_settings = isset($settings) ? $settings->get('cache') : array();
         $consistent_service_name = isset($cache_settings['default']) ? $cache_settings['default'] : 'cache.backend.database';
     }
     // Default the fast backend to APCu if it's available.
     if (!isset($fast_service_name) && function_exists('apcu_fetch')) {
         $fast_service_name = 'cache.backend.apcu';
     }
     $this->consistentServiceName = $consistent_service_name;
     // Do not use the fast chained backend during installation. In those cases,
     // we expect many cache invalidations and writes, the fast chained cache
     // backend performs badly in such a scenario.
     if (!drupal_installation_attempted()) {
         $this->fastServiceName = $fast_service_name;
     }
 }
예제 #5
0
 /**
  * Wrapper for drupal_installation_attempted().
  *
  * @return bool
  *   TRUE if a Drupal installation is currently being attempted.
  */
 protected function drupalInstallationAttempted()
 {
     return drupal_installation_attempted();
 }
예제 #6
0
 /**
  * Sets installation profile directories based on current site settings.
  *
  * @return $this
  */
 public function setProfileDirectoriesFromSettings()
 {
     $this->profileDirectories = array();
     $profile = drupal_get_profile();
     // For SimpleTest to be able to test modules packaged together with a
     // distribution we need to include the profile of the parent site (in
     // which test runs are triggered).
     if (drupal_valid_test_ua() && !drupal_installation_attempted()) {
         $testing_profile = \Drupal::config('simpletest.settings')->get('parent_profile');
         if ($testing_profile && $testing_profile != $profile) {
             $this->profileDirectories[] = drupal_get_path('profile', $testing_profile);
         }
     }
     // In case both profile directories contain the same extension, the actual
     // profile always has precedence.
     if ($profile) {
         $this->profileDirectories[] = drupal_get_path('profile', $profile);
     }
     return $this;
 }
예제 #7
0
/**
 * Adds accessibility attributes.
 */
function govcms_zen_preprocess_aria_invalid(&$variables)
{
    if (!empty($variables['element']['#required']) && !drupal_installation_attempted()) {
        $variables['element']['#attributes']['required'] = 'true';
    }
    if (isset($variables['element']['#parents']) && form_get_error($variables['element']) !== NULL && !empty($variables['element']['#validated'])) {
        $variables['element']['#attributes']['aria-invalid'] = 'true';
    }
}
예제 #8
0
 /**
  * Create a DrupalKernel object from a request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  * @param $class_loader
  *   The class loader. Normally Composer's ClassLoader, as included by the
  *   front controller, but may also be decorated; e.g.,
  *   \Symfony\Component\ClassLoader\ApcClassLoader.
  * @param string $environment
  *   String indicating the environment, e.g. 'prod' or 'dev'.
  * @param bool $allow_dumping
  *   (optional) FALSE to stop the container from being written to or read
  *   from disk. Defaults to TRUE.
  *
  * @return static
  *
  * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  *   In case the host name in the request is not trusted.
  */
 public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     $core_root = dirname(dirname(dirname(__DIR__)));
     require_once $core_root . '/includes/bootstrap.inc';
     $kernel = new static($environment, $class_loader, $allow_dumping);
     // Ensure sane php environment variables..
     static::bootEnvironment();
     // Get our most basic settings setup.
     $site_path = static::findSitePath($request);
     $kernel->setSitePath($site_path);
     Settings::initialize(dirname($core_root), $site_path, $class_loader);
     // Initialize our list of trusted HTTP Host headers to protect against
     // header attacks.
     $host_patterns = Settings::get('trusted_host_patterns', array());
     if (PHP_SAPI !== 'cli' && !empty($host_patterns)) {
         if (static::setupTrustedHosts($request, $host_patterns) === FALSE) {
             throw new BadRequestHttpException('The provided host name is not valid for this server.');
         }
     }
     // Redirect the user to the installation script if Drupal has not been
     // installed yet (i.e., if no $databases array has been defined in the
     // settings.php file) and we are not already installing.
     if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
         $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
         $response->prepare($request)->send();
     }
     return $kernel;
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     // Ensure sane PHP environment variables.
     static::bootEnvironment();
     try {
         $this->initializeSettings($request);
         // Redirect the user to the installation script if Drupal has not been
         // installed yet (i.e., if no $databases array has been defined in the
         // settings.php file) and we are not already installing.
         if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
             $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
         } else {
             $this->boot();
             $response = $this->getHttpKernel()->handle($request, $type, $catch);
         }
     } catch (\Exception $e) {
         if ($catch === FALSE) {
             throw $e;
         }
         $response = $this->handleException($e, $request, $type);
     }
     // Adapt response headers to the current request.
     $response->prepare($request);
     return $response;
 }
예제 #10
0
 /**
  * Updates the locale strings when a configuration override is saved/deleted.
  *
  * @param \Drupal\language\Config\LanguageConfigOverrideCrudEvent $event
  *   The language configuration event.
  */
 public function onOverrideChange(LanguageConfigOverrideCrudEvent $event)
 {
     // Only attempt to feed back configuration override changes to locale if
     // the update itself was not initiated by locale data changes.
     if (!drupal_installation_attempted() && !$this->localeConfigManager->isUpdatingTranslationsFromLocale()) {
         $translation_config = $event->getLanguageConfigOverride();
         $langcode = $translation_config->getLangcode();
         $reference_config = $this->configFactory->getEditable($translation_config->getName())->get();
         $this->updateLocaleStorage($translation_config, $langcode, $reference_config);
     }
 }
예제 #11
0
 /**
  * {@inheritdoc}
  */
 public function isApplicable()
 {
     return !drupal_installation_attempted() && $this->activation->isActive();
 }
 /**
  * Gets the configuration storage that provides the default configuration.
  *
  * @param string $collection
  *   (optional) The configuration collection. Defaults to the default
  *   collection.
  *
  * @return \Drupal\Core\Config\StorageInterface
  *   The configuration storage that provides the default configuration.
  */
 public function getSourceStorage($collection = StorageInterface::DEFAULT_COLLECTION)
 {
     if (!isset($this->sourceStorage)) {
         // Default to using the ExtensionInstallStorage which searches extension's
         // config directories for default configuration. Only include the profile
         // configuration during Drupal installation.
         $this->sourceStorage = new ExtensionInstallStorage($this->activeStorage, InstallStorage::CONFIG_INSTALL_DIRECTORY, $collection, drupal_installation_attempted());
     }
     if ($this->sourceStorage->getCollectionName() != $collection) {
         $this->sourceStorage = $this->sourceStorage->createCollection($collection);
     }
     return $this->sourceStorage;
 }
 /**
  * Create a DrupalKernel object from a request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  * @param $class_loader
  *   The class loader. Normally Composer's ClassLoader, as included by the
  *   front controller, but may also be decorated; e.g.,
  *   \Symfony\Component\ClassLoader\ApcClassLoader.
  * @param string $environment
  *   String indicating the environment, e.g. 'prod' or 'dev'.
  * @param bool $allow_dumping
  *   (optional) FALSE to stop the container from being written to or read
  *   from disk. Defaults to TRUE.
  *
  * @return static
  */
 public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc';
     $kernel = new static($environment, $class_loader, $allow_dumping);
     // Ensure sane php environment variables..
     static::bootEnvironment();
     // Get our most basic settings setup.
     $kernel->initializeSettings($request);
     // Redirect the user to the installation script if Drupal has not been
     // installed yet (i.e., if no $databases array has been defined in the
     // settings.php file) and we are not already installing.
     if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
         $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
         $response->prepare($request)->send();
     }
     return $kernel;
 }
예제 #14
0
 /**
  * Create a DrupalKernel object from a request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  * @param $class_loader
  *   The class loader. Normally Composer's ClassLoader, as included by the
  *   front controller, but may also be decorated; e.g.,
  *   \Symfony\Component\ClassLoader\ApcClassLoader.
  * @param string $environment
  *   String indicating the environment, e.g. 'prod' or 'dev'.
  * @param bool $allow_dumping
  *   (optional) FALSE to stop the container from being written to or read
  *   from disk. Defaults to TRUE.
  *
  * @return static
  *
  * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  *   In case the host name in the request is not trusted.
  */
 public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     $core_root = dirname(dirname(dirname(__DIR__)));
     require_once $core_root . '/includes/bootstrap.inc';
     $class_loader_class = get_class($class_loader);
     $kernel = new static($environment, $class_loader, $allow_dumping);
     // Ensure sane php environment variables..
     static::bootEnvironment();
     // Get our most basic settings setup.
     $site_path = static::findSitePath($request);
     $kernel->setSitePath($site_path);
     Settings::initialize(dirname($core_root), $site_path, $class_loader);
     // Initialize our list of trusted HTTP Host headers to protect against
     // header attacks.
     $host_patterns = Settings::get('trusted_host_patterns', array());
     if (PHP_SAPI !== 'cli' && !empty($host_patterns)) {
         if (static::setupTrustedHosts($request, $host_patterns) === FALSE) {
             throw new BadRequestHttpException('The provided host name is not valid for this server.');
         }
     }
     // Redirect the user to the installation script if Drupal has not been
     // installed yet (i.e., if no $databases array has been defined in the
     // settings.php file) and we are not already installing.
     if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
         $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
         $response->prepare($request)->send();
     }
     // If the class loader is still the same, possibly upgrade to the APC class
     // loader.
     if ($class_loader_class == get_class($class_loader) && Settings::get('class_loader_auto_detect', TRUE) && function_exists('apc_fetch')) {
         $prefix = Settings::getApcuPrefix('class_loader', $core_root);
         $apc_loader = new \Symfony\Component\ClassLoader\ApcClassLoader($prefix, $class_loader);
         $class_loader->unregister();
         $apc_loader->register();
         $class_loader = $apc_loader;
     }
     // Ensure that the class loader reference is up-to-date.
     $kernel->classLoader = $class_loader;
     return $kernel;
 }