/** * {@inheritdoc} */ public function getForm(EntityInterface $entity, $operation = 'default', array $form_state_additions = array()) { $form_object = $this->entityManager->getFormObject($entity->getEntityTypeId(), $operation); $form_object->setEntity($entity); $form_state = (new FormState())->setFormState($form_state_additions); return $this->formBuilder->buildForm($form_object, $form_state); }
/** * Presents an administrative comment listing. * * @param \Symfony\Component\HttpFoundation\Request $request * The request of the page. * @param string $type * The type of the overview form ('approval' or 'new') default to 'new'. * * @return array * Then comment multiple delete confirmation form or the comments overview * administration form. */ public function adminPage(Request $request, $type = 'new') { if ($request->request->get('operation') == 'delete' && $request->request->get('comments')) { return $this->formBuilder->getForm('\\Drupal\\comment\\Form\\ConfirmDeleteMultiple', $request); } else { return $this->formBuilder->getForm('\\Drupal\\comment\\Form\\CommentAdminOverview', $type); } }
/** * Constructs a morse request object. */ public function morse(Request $request, $type) { if ($type == "morse") { return $this->formBuilder->getForm('\\Drupal\\morse\\Form\\MorseConverter', $request); } else { return $this->formBuilder->getForm('\\Drupal\\morse\\Form\\AlphaNumericConverter', $request); } }
/** * {@inheritdoc} */ public function getForm(EntityInterface $entity, $operation = 'default', array $form_state = array()) { $form_object = $this->entityManager->getFormObject($entity->getEntityTypeId(), $operation); $form_object->setEntity($entity); $form_state['build_info']['callback_object'] = $form_object; $form_state['build_info']['base_form_id'] = $form_object->getBaseFormID(); $form_state['build_info'] += array('args' => array()); return $this->formBuilder->buildForm($form_object, $form_state); }
/** * Tests the getForm() method. * * @covers ::getForm() */ public function testGetForm() { $form_controller = $this->getMock('Drupal\\Core\\Entity\\EntityFormInterface'); $form_controller->expects($this->any())->method('getFormId')->will($this->returnValue('the_form_id')); $this->entityManager->expects($this->any())->method('getFormObject')->with('the_entity_type', 'default')->will($this->returnValue($form_controller)); $this->formBuilder->expects($this->once())->method('buildForm')->with($form_controller, $this->isInstanceOf('Drupal\\Core\\Form\\FormStateInterface'))->will($this->returnValue('the form contents')); $entity = $this->getMock('Drupal\\Core\\Entity\\EntityInterface'); $entity->expects($this->once())->method('getEntityTypeId')->will($this->returnValue('the_entity_type')); $this->assertSame('the form contents', $this->entityFormBuilder->getForm($entity)); }
/** * Invokes the form and returns the result. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * * @return array * The render array that results from invoking the controller. */ public function getContentResult(Request $request) { $form_object = $this->getFormObject($request, $this->formDefinition); // Add the form and form_state to trick the getArguments method of the // controller resolver. $form_state = array(); $request->attributes->set('form', array()); $request->attributes->set('form_state', $form_state); $args = $this->controllerResolver->getArguments($request, array($form_object, 'buildForm')); $request->attributes->remove('form'); $request->attributes->remove('form_state'); // Remove $form and $form_state from the arguments, and re-index them. unset($args[0], $args[1]); $form_state['build_info']['args'] = array_values($args); return $this->formBuilder->buildForm($form_object, $form_state); }
/** * Form based configuration data inspection. * * @param string $name * Configuration name. * * @return array * A render array for a form view. */ public function getForm($name) { $config_schema = $this->configInspectorManager->getConfigSchema($name); $output = $this->formBuilder->getForm('\\Drupal\\config_inspector\\Form\\ConfigInspectorItemForm', $config_schema); $output['#title'] = $this->t('Raw configuration data for %name', array('%name' => $name)); return $output; }
/** * Gets a form submitted via #ajax during an Ajax callback. * * This will load a form from the form cache used during Ajax operations. It * pulls the form info from the request body. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request object. * * @return \Drupal\system\FileAjaxForm * A wrapper object containing the $form, $form_state, $form_id, * $form_build_id and an initial list of Ajax $commands. * * @throws \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface */ protected function getForm(Request $request) { $form_state = new FormState(); $form_build_id = $request->request->get('form_build_id'); // Get the form from the cache. $form = $this->formBuilder->getCache($form_build_id, $form_state); if (!$form) { // If $form cannot be loaded from the cache, the form_build_id must be // invalid, which means that someone performed a POST request onto // system/ajax without actually viewing the concerned form in the browser. // This is likely a hacking attempt as it never happens under normal // circumstances. $this->logger->warning('Invalid form POST data.'); throw new BadRequestHttpException(); } // Since some of the submit handlers are run, redirects need to be disabled. $form_state->disableRedirect(); // When a form is rebuilt after Ajax processing, its #build_id and #action // should not change. // @see \Drupal\Core\Form\FormBuilderInterface::rebuildForm() $form_state->addRebuildInfo('copy', ['#build_id' => TRUE, '#action' => TRUE]); // The form needs to be processed; prepare for that by setting a few // internal variables. $form_state->setUserInput($request->request->all()); $form_id = $form['#form_id']; return new FileAjaxForm($form, $form_state, $form_id, $form['#build_id'], []); }
/** * Displays a listing of database log messages. * * Messages are truncated at 56 chars. * Full-length messages can be viewed on the message details page. * * @return array * A render array as expected by drupal_render(). * * @see dblog_clear_log_form() * @see dblog_event() */ public function overview() { $filter = $this->buildFilterQuery(); $rows = array(); $classes = static::getLogLevelClassMap(); $this->moduleHandler->loadInclude('dblog', 'admin.inc'); $build['dblog_filter_form'] = $this->formBuilder->getForm('Drupal\\dblog\\Form\\DblogFilterForm'); $build['dblog_clear_log_form'] = $this->formBuilder->getForm('Drupal\\dblog\\Form\\DblogClearLogForm'); $header = array('', array('data' => $this->t('Type'), 'field' => 'w.type', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), array('data' => $this->t('Date'), 'field' => 'w.wid', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)), $this->t('Message'), array('data' => $this->t('User'), 'field' => 'u.name', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), array('data' => $this->t('Operations'), 'class' => array(RESPONSIVE_PRIORITY_LOW))); $query = $this->database->select('watchdog', 'w')->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender'); $query->fields('w', array('wid', 'uid', 'severity', 'type', 'timestamp', 'message', 'variables', 'link')); if (!empty($filter['where'])) { $query->where($filter['where'], $filter['args']); } $result = $query->limit(50)->orderByHeader($header)->execute(); foreach ($result as $dblog) { $message = $this->formatMessage($dblog); if ($message && isset($dblog->wid)) { // Truncate link_text to 56 chars of message. $log_text = Unicode::truncate(Xss::filter($message, array()), 56, TRUE, TRUE); $message = $this->l($log_text, 'dblog.event', array('event_id' => $dblog->wid), array('html' => TRUE)); } $username = array('#theme' => 'username', '#account' => user_load($dblog->uid)); $rows[] = array('data' => array(array('class' => array('icon')), $this->t($dblog->type), $this->dateFormatter->format($dblog->timestamp, 'short'), $message, array('data' => $username), Xss::filter($dblog->link)), 'class' => array(drupal_html_class('dblog-' . $dblog->type), $classes[$dblog->severity])); } $build['dblog_table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => array('id' => 'admin-dblog', 'class' => array('admin-dblog')), '#empty' => $this->t('No log messages available.'), '#attached' => array('library' => array('dblog/drupal.dblog'))); $build['dblog_pager'] = array('#theme' => 'pager'); return $build; }
/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { // @todo Use a lazy_builder. $product = $items->getEntity(); $settings = $this->getSettings(); return $this->formBuilder->getForm('\\Drupal\\commerce_product\\Form\\AddToCartForm', $product, $settings); }
/** * Displays a listing of database log messages. * * Messages are truncated at 56 chars. * Full-length messages can be viewed on the message details page. * * @return array * A render array as expected by drupal_render(). * * @see dblog_clear_log_form() * @see dblog_event() */ public function overview() { $filter = $this->buildFilterQuery(); $rows = array(); $classes = static::getLogLevelClassMap(); $this->moduleHandler->loadInclude('dblog', 'admin.inc'); $build['dblog_filter_form'] = $this->formBuilder->getForm('Drupal\\dblog\\Form\\DblogFilterForm'); $build['dblog_clear_log_form'] = $this->formBuilder->getForm('Drupal\\dblog\\Form\\DblogClearLogForm'); $header = array('', array('data' => $this->t('Type'), 'field' => 'w.type', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), array('data' => $this->t('Date'), 'field' => 'w.wid', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)), $this->t('Message'), array('data' => $this->t('User'), 'field' => 'ufd.name', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), array('data' => $this->t('Operations'), 'class' => array(RESPONSIVE_PRIORITY_LOW))); $query = $this->database->select('watchdog', 'w')->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender'); $query->fields('w', array('wid', 'uid', 'severity', 'type', 'timestamp', 'message', 'variables', 'link')); $query->leftJoin('users_field_data', 'ufd', 'w.uid = ufd.uid'); if (!empty($filter['where'])) { $query->where($filter['where'], $filter['args']); } $result = $query->limit(50)->orderByHeader($header)->execute(); foreach ($result as $dblog) { $message = $this->formatMessage($dblog); if ($message && isset($dblog->wid)) { $title = Unicode::truncate(Html::decodeEntities(strip_tags($message)), 256, TRUE, TRUE); $log_text = Unicode::truncate($title, 56, TRUE, TRUE); // The link generator will escape any unsafe HTML entities in the final // text. $message = $this->l($log_text, new Url('dblog.event', array('event_id' => $dblog->wid), array('attributes' => array('title' => $title)))); } $username = array('#theme' => 'username', '#account' => $this->userStorage->load($dblog->uid)); $rows[] = array('data' => array(array('class' => array('icon')), $this->t($dblog->type), $this->dateFormatter->format($dblog->timestamp, 'short'), $message, array('data' => $username), array('data' => array('#markup' => $dblog->link))), 'class' => array(Html::getClass('dblog-' . $dblog->type), $classes[$dblog->severity])); } $build['dblog_table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => array('id' => 'admin-dblog', 'class' => array('admin-dblog')), '#empty' => $this->t('No log messages available.'), '#attached' => array('library' => array('dblog/drupal.dblog'))); $build['dblog_pager'] = array('#type' => 'pager'); return $build; }
/** * Simulates a form submission within a request, bypassing submitForm(). * * Calling submitForm() will reset the form builder, if two forms were on the * same page, they will be submitted simultaneously. * * @param string $form_id * The unique string identifying the form. * @param \Drupal\Core\Form\FormInterface $form_arg * The form object. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param bool $programmed * Whether $form_state->setProgrammed() should be passed TRUE or not. If it * is not set to TRUE, you must provide additional data in $form_state for * the submission to take place. * * @return array * The built form. */ protected function simulateFormSubmission($form_id, FormInterface $form_arg, FormStateInterface $form_state, $programmed = TRUE) { $input = $form_state->getUserInput(); $input['op'] = 'Submit'; $form_state->setUserInput($input)->setProgrammed($programmed)->setSubmitted(); return $this->formBuilder->buildForm($form_arg, $form_state); }
/** * Invokes the form and returns the result. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match. * * @return array * The render array that results from invoking the controller. */ public function getContentResult(Request $request, RouteMatchInterface $route_match) { $form_arg = $this->getFormArgument($route_match); $form_object = $this->getFormObject($route_match, $form_arg); // Add the form and form_state to trick the getArguments method of the // controller resolver. $form_state = new FormState(); $request->attributes->set('form', []); $request->attributes->set('form_state', $form_state); $args = $this->controllerResolver->getArguments($request, [$form_object, 'buildForm']); $request->attributes->remove('form'); $request->attributes->remove('form_state'); // Remove $form and $form_state from the arguments, and re-index them. unset($args[0], $args[1]); $form_state->addBuildInfo('args', array_values($args)); return $this->formBuilder->buildForm($form_object, $form_state); }
/** * Act on entities being assembled before rendering. * * This is a hook bridge. * * @see hook_entity_view() * @see EntityFieldManagerInterface::getExtraFields() */ public function entityView(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { if (!$this->moderationInfo->isModeratableEntity($entity)) { return; } if (!$this->moderationInfo->isLatestRevision($entity)) { return; } /** @var ContentEntityInterface $entity */ if ($entity->isDefaultRevision()) { return; } $component = $display->getComponent('workbench_moderation_control'); if ($component) { $build['workbench_moderation_control'] = $this->formBuilder->getForm(EntityModerationForm::class, $entity); $build['workbench_moderation_control']['#weight'] = $component['weight']; } }
/** * {@inheritdoc} */ public function getWizardForm(FormWizardInterface $wizard, array $parameters = [], $ajax = FALSE) { $form_state = $this->getFormState($wizard, $parameters, $ajax); $form = $this->builder->buildForm($wizard, $form_state); if ($ajax) { $form['#attached']['library'][] = 'core/drupal.dialog.ajax'; $status_messages = array('#type' => 'status_messages'); // @todo properly inject the renderer. Core should really be doing this work. if ($messages = \Drupal::service('renderer')->renderRoot($status_messages)) { if (!empty($form['#prefix'])) { // Form prefix is expected to be a string. Prepend the messages to // that string. $form['#prefix'] = '<div class="wizard-messages">' . $messages . '</div>' . $form['#prefix']; } } } return $form; }
/** * Simulates a form submission within a request, bypassing submitForm(). * * Calling submitForm() will reset the form builder, if two forms were on the * same page, they will be submitted simultaneously. * * @param string $form_id * The unique string identifying the form. * @param \Drupal\Core\Form\FormInterface $form_arg * The form object. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param bool $programmed * Whether $form_state['programmed'] should be set to TRUE or not. If it is * not set to TRUE, you must provide additional data in $form_state for the * submission to take place. * * @return array * The built form. */ protected function simulateFormSubmission($form_id, FormInterface $form_arg, FormStateInterface $form_state, $programmed = TRUE) { $form_state['build_info']['callback_object'] = $form_arg; $form_state['build_info']['args'] = array(); $form_state['input']['op'] = 'Submit'; $form_state['programmed'] = $programmed; $form_state['submitted'] = TRUE; return $this->formBuilder->buildForm($form_arg, $form_state); }
/** * {@inheritdoc} */ public function build() { $links = $this->switchUserList(); if (!empty($links)) { $build = array('devel_links' => array('#theme' => 'links', '#links' => $links), '#attached' => array('css' => array(drupal_get_path('module', 'devel') . '/css/devel.css'))); if ($this->configuration['show_form']) { $build['devel_form'] = $this->formBuilder->getForm('\\Drupal\\devel\\Form\\SwitchUserForm'); } return $build; } }
/** * {@inheritdoc} */ public function build() { $build = []; if ($accounts = $this->getUsers()) { $build['devel_links'] = $this->buildUserList($accounts); if ($this->configuration['show_form']) { $build['devel_form'] = $this->formBuilder->getForm('\\Drupal\\devel\\Form\\SwitchUserForm'); } } return $build; }
public function addRelationship(array &$form, FormStateInterface $form_state) { $relationship = $form_state->getValue('relationships'); $content = $this->formBuilder->getForm($this->getRelationshipClass(), $relationship, $this->getTempstoreId(), $this->machine_name); $content['#attached']['library'][] = 'core/drupal.dialog.ajax'; $cached_values = $form_state->getTemporaryValue('wizard'); list(, $route_parameters) = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $relationship); $content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getRelationshipAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]); $response = new AjaxResponse(); $response->addCommand(new OpenModalDialogCommand($this->t('Configure Relationship'), $content, array('width' => '700'))); return $response; }
/** * @covers ::execute */ public function testExecute() { $bundle_exists = $this->randomMachineName(); $bundle_exists_definition = ['configuration_form' => $this->randomMachineName()]; $bundle_exists_no_form = $this->randomMachineName(); $bundle_exists_no_form_definition = []; $bundle_no_exists = $this->randomMachineName(); $bundle_no_exists_definition = NULL; $form_build = ['#type' => $this->randomMachineName()]; $this->formBuilder->expects($this->once())->method('getForm')->with($bundle_exists_definition['configuration_form'])->willReturn($form_build); $map = [[$bundle_exists, FALSE, $bundle_exists_definition], [$bundle_exists_no_form, FALSE, $bundle_exists_no_form_definition], [$bundle_no_exists, FALSE, $bundle_no_exists_definition]]; $this->paymentTypeManager->expects($this->any())->method('getDefinition')->willReturnMap($map); // Test with a bundle of a plugin with a form. $build = $this->sut->execute($bundle_exists); $this->assertSame($form_build, $build); // Test with a bundle of a plugin without a form. $build = $this->sut->execute($bundle_exists_no_form); $this->assertInternalType('array', $build); // Test with a non-existing bundle. $this->setExpectedException(NotFoundHttpException::class); $this->sut->execute($bundle_no_exists); }
/** * * * @return array * A render array. */ public function show() { $build['#tree'] = TRUE; // Form that provides operations. $build['file_action_form'] = $this->formBuilder->getForm('Drupal\\uc_file\\Form\\FileActionForm'); // Table of files to operate on. $header = array('filename' => array('data' => $this->t('File'), 'field' => 'f.filename', 'sort' => 'asc'), 'title' => array('data' => $this->t('Product'), 'field' => 'n.title'), 'model' => array('data' => $this->t('SKU'), 'field' => 'fp.model', 'class' => array(RESPONSIVE_PRIORITY_LOW))); // Create pager. $query = $this->database->select('uc_files', 'f')->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')->extend('Drupal\\Core\\Database\\Query\\TableSortExtender')->orderByHeader($header)->limit(UC_FILE_PAGER_SIZE); $query->leftJoin('uc_file_products', 'fp', 'f.fid = fp.fid'); $query->leftJoin('uc_product_features', 'pf', 'fp.pfid = pf.pfid'); $query->leftJoin('node_field_data', 'n', 'pf.nid = n.nid'); $query->addField('n', 'nid'); $query->addField('f', 'filename'); $query->addField('n', 'title'); $query->addField('fp', 'model'); $query->addField('f', 'fid'); $query->addField('pf', 'pfid'); $count_query = $this->database->select('uc_files'); $count_query->addExpression('COUNT(*)'); $query->setCountQuery($count_query); $result = $query->execute(); $options = array(); foreach ($result as $file) { // All files are shown here, including files which are not attached to products. if (isset($file->nid)) { $options[$file->fid] = array('filename' => array('data' => array('#plain_text' => $file->filename), 'class' => is_dir(uc_file_qualify_file($file->filename)) ? array('uc-file-directory-view') : array()), 'title' => array('data' => array('#type' => 'link', '#title' => $file->title, '#url' => Url::fromRoute('entity.node.canonical', ['node' => $file->nid]))), 'model' => array('data' => array('#plain_text' => $file->model))); } else { $options[$file->fid] = array('filename' => array('data' => array('#plain_text' => $file->filename), 'class' => is_dir(uc_file_qualify_file($file->filename)) ? array('uc-file-directory-view') : array()), 'title' => '', 'model' => ''); } } // Create checkboxes for each file. $build['file_select'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options, '#empty' => $this->t('No file downloads available.')); $build['file_select_pager'] = array('#type' => 'pager'); return $build; }
/** * Form submission handler for the entity selection step. * * On success will send the user to the next step of the form to select the * embed display settings. On form errors, this will rebuild the form and * display the error messages. * * @param array $form * The form array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. * * @return \Drupal\Core\Ajax\AjaxResponse * The ajax response. */ public function submitSelectStep(array &$form, FormStateInterface $form_state) { $response = new AjaxResponse(); // Display errors in form, if any. if ($form_state->hasAnyErrors()) { unset($form['#prefix'], $form['#suffix']); $form['status_messages'] = array('#type' => 'status_messages', '#weight' => -10); $response->addCommand(new HtmlCommand('#entity-embed-dialog-form', $form)); } else { $form_state->set('step', !empty($this->entityBrowserSettings['display_review']) ? 'review' : 'embed'); $form_state->setRebuild(TRUE); $rebuild_form = $this->formBuilder->rebuildForm('entity_embed_dialog', $form_state, $form); unset($rebuild_form['#prefix'], $rebuild_form['#suffix']); $response->addCommand(new HtmlCommand('#entity-embed-dialog-form', $rebuild_form)); } return $response; }
/** * {@inheritdoc} */ public function build() { $build['#cache'] = ['max-age' => 0]; // $headers = array( // array('data' => t('node'), 'style' => 'text-align:right;'), // array('data' => t('prio'), 'style' => 'text-align:right;'), // t('status'), // t('realm'), // array('data' => t('gid'), 'style' => 'text-align:right;'), // t('view'), // t('update'), // t('delete'), // t('explained'), // ); // $rows[] = array('data' => array(array('data' => 1, 'style' => 'background-color: red; color: blue'), // "CACHE 5", 3, 4, 5)); if (empty(self::visibleNodes())) { $request_uri = \Drupal::request()->getRequestUri(); if ($request_uri === '/' || $request_uri === '/node') { $build['#markup'] = t('@node_access information is not available for the nodes on this page due to caching — flush your caches to display it.', self::NODE_ACCESS); } return $build; } $build['#title'] = t('@node_access entries for nodes shown on this page', self::NODE_ACCESS); // $build['test_table'] = array( // '#type' => 'table', // '#header' => $headers, // // array( // // t('Column 0'), // // array('data' => t('Active'), 'colspan' => '2'), // // array('data' => t('Staged'), 'colspan' => '2'), // // ), // '#rows' => $rows, // '#empty' => $this->t('No records found!'), // '#responsive' => FALSE, // '#attributes' => array( // 'class' => array(), // 'style' => 'text-align: left;', // ), // ); $build['dna_form'] = $this->formBuilder->getForm('\\Drupal\\devel_node_access\\Form\\DnaForm'); return $build; }
/** * Gets a form submitted via #ajax during an Ajax callback. * * This will load a form from the form cache used during Ajax operations. It * pulls the form info from the request body. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request object. * * @return \Drupal\system\FileAjaxForm * A wrapper object containing the $form, $form_state, $form_id, * $form_build_id and an initial list of Ajax $commands. * * @throws \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface */ protected function getForm(Request $request) { $form_state = new FormState(); $form_build_id = $request->request->get('form_build_id'); // Get the form from the cache. $form = $this->formBuilder->getCache($form_build_id, $form_state); if (!$form) { // If $form cannot be loaded from the cache, the form_build_id must be // invalid, which means that someone performed a POST request onto // system/ajax without actually viewing the concerned form in the browser. // This is likely a hacking attempt as it never happens under normal // circumstances. $this->logger->warning('Invalid form POST data.'); throw new BadRequestHttpException(); } // When a page level cache is enabled, the form-build id might have been // replaced from within \Drupal::formBuilder()->getCache(). If this is the // case, it is also necessary to update it in the browser by issuing an // appropriate Ajax command. $commands = []; if (isset($form['#build_id_old']) && $form['#build_id_old'] != $form['#build_id']) { // If the form build ID has changed, issue an Ajax command to update it. $commands[] = new UpdateBuildIdCommand($form['#build_id_old'], $form['#build_id']); $form_build_id = $form['#build_id']; } // Since some of the submit handlers are run, redirects need to be disabled. $form_state->disableRedirect(); // When a form is rebuilt after Ajax processing, its #build_id and #action // should not change. // @see \Drupal\Core\Form\FormBuilderInterface::rebuildForm() $form_state->addRebuildInfo('copy', ['#build_id' => TRUE, '#action' => TRUE]); // The form needs to be processed; prepare for that by setting a few // internal variables. $form_state->setUserInput($request->request->all()); $form_id = $form['#form_id']; return new FileAjaxForm($form, $form_state, $form_id, $form_build_id, $commands); }
/** * {@inheritdoc} * * @param string|null $theme * (optional) The theme to display the blocks for. If NULL, the current * theme will be used. * @param \Symfony\Component\HttpFoundation\Request $request * The current request. * * @return array * The block list as a renderable array. */ public function render($theme = NULL, Request $request = NULL) { $this->request = $request; $this->theme = $theme; return $this->formBuilder->getForm($this); }
/** * {@inheritdoc} */ public function build() { return $this->formBuilder->getForm('Drupal\\masquerade\\Form\\MasqueradeForm'); }
/** * Returns a theme listing. * * @return string * An HTML string of the theme listing page. * * @todo Move into ThemeController. */ public function themesPage() { $config = $this->config('system.theme'); // Get all available themes. $themes = $this->themeHandler->rebuildThemeData(); uasort($themes, 'system_sort_modules_by_info_name'); $theme_default = $config->get('default'); $theme_groups = array('installed' => array(), 'uninstalled' => array()); $admin_theme = $config->get('admin'); $admin_theme_options = array(); foreach ($themes as &$theme) { if (!empty($theme->info['hidden'])) { continue; } $theme->is_default = $theme->getName() == $theme_default; $theme->is_admin = $theme->getName() == $admin_theme || $theme->is_default && $admin_theme == '0'; // Identify theme screenshot. $theme->screenshot = NULL; // Create a list which includes the current theme and all its base themes. if (isset($themes[$theme->getName()]->base_themes)) { $theme_keys = array_keys($themes[$theme->getName()]->base_themes); $theme_keys[] = $theme->getName(); } else { $theme_keys = array($theme->getName()); } // Look for a screenshot in the current theme or in its closest ancestor. foreach (array_reverse($theme_keys) as $theme_key) { if (isset($themes[$theme_key]) && file_exists($themes[$theme_key]->info['screenshot'])) { $theme->screenshot = array('uri' => $themes[$theme_key]->info['screenshot'], 'alt' => $this->t('Screenshot for !theme theme', array('!theme' => $theme->info['name'])), 'title' => $this->t('Screenshot for !theme theme', array('!theme' => $theme->info['name'])), 'attributes' => array('class' => array('screenshot'))); break; } } if (empty($theme->status)) { // Ensure this theme is compatible with this version of core. // Require the 'content' region to make sure the main page // content has a common place in all themes. $theme->incompatible_core = !isset($theme->info['core']) || $theme->info['core'] != \DRUPAL::CORE_COMPATIBILITY || !isset($theme->info['regions']['content']); $theme->incompatible_php = version_compare(phpversion(), $theme->info['php']) < 0; // Confirmed that the base theme is available. $theme->incompatible_base = isset($theme->info['base theme']) && !isset($themes[$theme->info['base theme']]); // Confirm that the theme engine is available. $theme->incompatible_engine = isset($theme->info['engine']) && !isset($theme->owner); } $theme->operations = array(); if (!empty($theme->status) || !$theme->incompatible_core && !$theme->incompatible_php && !$theme->incompatible_base && !$theme->incompatible_engine) { // Create the operations links. $query['theme'] = $theme->getName(); if ($this->themeAccess->checkAccess($theme->getName())) { $theme->operations[] = array('title' => $this->t('Settings'), 'url' => Url::fromRoute('system.theme_settings_theme', ['theme' => $theme->getName()]), 'attributes' => array('title' => $this->t('Settings for !theme theme', array('!theme' => $theme->info['name'])))); } if (!empty($theme->status)) { if (!$theme->is_default) { $theme_uninstallable = TRUE; if ($theme->getName() == $admin_theme) { $theme_uninstallable = FALSE; } // Check it isn't the base of theme of an installed theme. foreach ($theme->required_by as $themename => $dependency) { if (!empty($themes[$themename]->status)) { $theme_uninstallable = FALSE; } } if ($theme_uninstallable) { $theme->operations[] = array('title' => $this->t('Uninstall'), 'url' => Url::fromRoute('system.theme_uninstall'), 'query' => $query, 'attributes' => array('title' => $this->t('Uninstall !theme theme', array('!theme' => $theme->info['name'])))); } $theme->operations[] = array('title' => $this->t('Set as default'), 'url' => Url::fromRoute('system.theme_set_default'), 'query' => $query, 'attributes' => array('title' => $this->t('Set !theme as default theme', array('!theme' => $theme->info['name'])))); } $admin_theme_options[$theme->getName()] = $theme->info['name']; } else { $theme->operations[] = array('title' => $this->t('Install'), 'url' => Url::fromRoute('system.theme_install'), 'query' => $query, 'attributes' => array('title' => $this->t('Install !theme theme', array('!theme' => $theme->info['name'])))); $theme->operations[] = array('title' => $this->t('Install and set as default'), 'url' => Url::fromRoute('system.theme_set_default'), 'query' => $query, 'attributes' => array('title' => $this->t('Install !theme as default theme', array('!theme' => $theme->info['name'])))); } } // Add notes to default and administration theme. $theme->notes = array(); if ($theme->is_default) { $theme->notes[] = $this->t('default theme'); } if ($theme->is_admin) { $theme->notes[] = $this->t('admin theme'); } // Sort installed and uninstalled themes into their own groups. $theme_groups[$theme->status ? 'installed' : 'uninstalled'][] = $theme; } // There are two possible theme groups. $theme_group_titles = array('installed' => $this->formatPlural(count($theme_groups['installed']), 'Installed theme', 'Installed themes')); if (!empty($theme_groups['uninstalled'])) { $theme_group_titles['uninstalled'] = $this->formatPlural(count($theme_groups['uninstalled']), 'Uninstalled theme', 'Uninstalled themes'); } uasort($theme_groups['installed'], 'system_sort_themes'); $this->moduleHandler()->alter('system_themes_page', $theme_groups); $build = array(); $build[] = array('#theme' => 'system_themes_page', '#theme_groups' => $theme_groups, '#theme_group_titles' => $theme_group_titles); $build[] = $this->formBuilder->getForm('Drupal\\system\\Form\\ThemeAdminForm', $admin_theme_options); return $build; }
/** * {@inheritdoc} */ public function build() { return $this->formBuilder->getForm('Drupal\\form_test\\Form\\RedirectBlockForm'); }
/** * {@inheritdoc} */ public function build() { return $this->formBuilder->getForm($this); }