コード例 #1
0
ファイル: HeadlessConfigForm.php プロジェクト: nuxy/headless
 /**
  * Implements \Drupal\Core\Form\FormInterface::buildForm().
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('headless.config');
     $form['routing'] = array('#type' => 'details', '#title' => $this->t('Routing'), '#description' => $this->t('This is the publicly accessible path to User operation routes.'), '#open' => TRUE);
     $routing_path = $config->get('routing_path');
     if (empty($routing_path)) {
         $routing_path = 'headless';
     }
     $form['routing']['routing_path'] = array('#type' => 'textfield', '#title' => $this->t('Path'), '#size' => 55, '#maxlength' => 55, '#default_value' => $routing_path, '#required' => TRUE, '#field_prefix' => $this->requestContext->getCompleteBaseUrl() . '/');
     return parent::buildForm($form, $form_state);
 }
コード例 #2
0
 /**
  * Matches a path in the router.
  *
  * @param string $path
  *   The request path.
  * @param array $exclude
  *   An array of paths or system paths to skip.
  *
  * @return \Symfony\Component\HttpFoundation\Request
  *   A populated request object or NULL if the path couldn't be matched.
  */
 protected function getRequestForPath($path, array $exclude)
 {
     if (!empty($exclude[$path])) {
         return NULL;
     }
     // @todo Use the RequestHelper once https://drupal.org/node/2090293 is
     //   fixed.
     $request = Request::create($this->context->getCompleteBaseUrl() . '/' . $path);
     // Performance optimization: set a short accept header to reduce overhead in
     // AcceptHeaderMatcher when matching the request.
     $request->headers->set('Accept', 'text/html');
     // Find the system path by resolving aliases, language prefix, etc.
     $processed = $this->pathProcessor->processInbound($path, $request);
     if (empty($processed) || !empty($exclude[$processed])) {
         // This resolves to the front page, which we already add.
         return NULL;
     }
     $this->currentPath->setPath('/' . $processed, $request);
     // Attempt to match this path to provide a fully built request.
     try {
         $request->attributes->add($this->router->matchRequest($request));
         return $request;
     } catch (ParamNotConvertedException $e) {
         return NULL;
     } catch (ResourceNotFoundException $e) {
         return NULL;
     } catch (MethodNotAllowedException $e) {
         return NULL;
     } catch (AccessDeniedHttpException $e) {
         return NULL;
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $site_config = $this->config('system.site');
     $site_mail = $site_config->get('mail');
     if (empty($site_mail)) {
         $site_mail = ini_get('sendmail_from');
     }
     $form['site_information'] = array('#type' => 'details', '#title' => t('Site details'), '#open' => TRUE);
     $form['site_information']['site_name'] = array('#type' => 'textfield', '#title' => t('Site name'), '#default_value' => $site_config->get('name'), '#required' => TRUE);
     $form['site_information']['site_slogan'] = array('#type' => 'textfield', '#title' => t('Slogan'), '#default_value' => $site_config->get('slogan'), '#description' => t("How this is used depends on your site's theme."));
     $form['site_information']['site_mail'] = array('#type' => 'email', '#title' => t('Email address'), '#default_value' => $site_mail, '#description' => t("The <em>From</em> address in automated emails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this email being flagged as spam.)"), '#required' => TRUE);
     $form['front_page'] = array('#type' => 'details', '#title' => t('Front page'), '#open' => TRUE);
     $front_page = $site_config->get('page.front') != '/user/login' ? $this->aliasManager->getAliasByPath($site_config->get('page.front')) : '';
     $form['front_page']['site_frontpage'] = array('#type' => 'textfield', '#title' => t('Default front page'), '#default_value' => $front_page, '#size' => 40, '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default front page.'), '#field_prefix' => $this->requestContext->getCompleteBaseUrl());
     $form['error_page'] = array('#type' => 'details', '#title' => t('Error pages'), '#open' => TRUE);
     $form['error_page']['site_403'] = array('#type' => 'textfield', '#title' => t('Default 403 (access denied) page'), '#default_value' => $site_config->get('page.403'), '#size' => 40, '#description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.'));
     $form['error_page']['site_404'] = array('#type' => 'textfield', '#title' => t('Default 404 (not found) page'), '#default_value' => $site_config->get('page.404'), '#size' => 40, '#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.'));
     return parent::buildForm($form, $form_state);
 }
コード例 #4
0
ファイル: PathFormBase.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL)
 {
     $this->path = $this->buildPath($pid);
     $form['source'] = array('#type' => 'textfield', '#title' => $this->t('Existing system path'), '#default_value' => $this->path['source'], '#maxlength' => 255, '#size' => 45, '#description' => $this->t('Specify the existing path you wish to alias. For example: /node/28, /forum/1, /taxonomy/term/1.'), '#field_prefix' => $this->requestContext->getCompleteBaseUrl(), '#required' => TRUE);
     $form['alias'] = array('#type' => 'textfield', '#title' => $this->t('Path alias'), '#default_value' => $this->path['alias'], '#maxlength' => 255, '#size' => 45, '#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page. Use a relative path with a slash in front..'), '#field_prefix' => $this->requestContext->getCompleteBaseUrl(), '#required' => TRUE);
     // A hidden value unless language.module is enabled.
     if (\Drupal::moduleHandler()->moduleExists('language')) {
         $languages = \Drupal::languageManager()->getLanguages();
         $language_options = array();
         foreach ($languages as $langcode => $language) {
             $language_options[$langcode] = $language->getName();
         }
         $form['langcode'] = array('#type' => 'select', '#title' => $this->t('Language'), '#options' => $language_options, '#empty_value' => LanguageInterface::LANGCODE_NOT_SPECIFIED, '#empty_option' => $this->t('- None -'), '#default_value' => $this->path['langcode'], '#weight' => -10, '#description' => $this->t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set as <em>- None -</em>.'));
     } else {
         $form['langcode'] = array('#type' => 'value', '#value' => $this->path['langcode']);
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'));
     return $form;
 }