本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::getBuildInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::getBuildInfo方法的具体用法?PHP FormStateInterface::getBuildInfo怎么用?PHP FormStateInterface::getBuildInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::getBuildInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTheme
/**
* Retrieves the currently selected theme on the settings form.
*
* @param array $form
* Nested array of form elements that comprise the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\bootstrap\Theme|FALSE
* The currently selected theme object or FALSE if not a Bootstrap theme.
*/
public static function getTheme(array &$form, FormStateInterface $form_state)
{
$build_info = $form_state->getBuildInfo();
$theme = isset($build_info['args'][0]) ? Bootstrap::getTheme($build_info['args'][0]) : FALSE;
// Do not continue if the theme is not Bootstrap specific.
if (!$theme || !$theme->subthemeOf('bootstrap')) {
unset($form['#submit'][0]);
unset($form['#validate'][0]);
}
return $theme;
}
示例2: applyAccountFormProtection
/**
* {@inheritdoc}
*/
public function applyAccountFormProtection(array &$form, FormStateInterface $form_state)
{
$build_info = $form_state->getBuildInfo();
$account = $build_info['callback_object']->getEntity();
if (isset($form['account']['status'])) {
$form['account']['status']['#disabled'] = TRUE;
$form['account']['status']['#value'] = $account->isActive();
return TRUE;
}
return FALSE;
}
示例3: applyAccountFormProtection
/**
* {@inheritdoc}
*/
public function applyAccountFormProtection(array &$form, FormStateInterface $form_state)
{
$build_info = $form_state->getBuildInfo();
$account = $build_info['callback_object']->getEntity();
// If for some reason the account has no mail, then don't protect it.
if ($account->getEmail() && isset($form['account']['mail'])) {
$form['account']['mail']['#disabled'] = TRUE;
$form['account']['mail']['#value'] = $account->getEmail();
return TRUE;
}
return FALSE;
}
示例4: submitForm
public function submitForm(array &$form, FormStateInterface $form_state)
{
try {
if (!empty($form_state->getBuildInfo()['args'][0]) && !empty($form_state->getBuildInfo()['args'][1])) {
$smfSessionId = $form_state->getBuildInfo()['args'][0];
/**
* @var \Drupal\smfbridge\Smf\Member $smfMember
*/
$smfMember = \Drupal::service('smfbridge.smfmember');
if ($smfMember->setAdminTime($smfSessionId)) {
$form_state->setRedirectUrl(Url::fromUserInput($form_state->getBuildInfo()['args'][1]));
} else {
throw new \Exception($this->t('Failed to get access to SMF admin area.'));
}
} else {
throw new \Exception($this->t('Failed to get access to SMF admin area.'));
}
} catch (\Exception $e) {
drupal_set_message($e->getMessage(), 'error');
}
}
示例5: buildForm
/**
* {@inheritdoc}.
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$build_info = $form_state->getBuildInfo();
if ($build_info['args'] && $build_info['args'][0] instanceof EntityInterface) {
$this->entity = $build_info['args'][0];
}
$form['first_name'] = array('#type' => 'textfield', '#title' => $this->t('First name'));
$form['last_name'] = array('#type' => 'textfield', '#title' => $this->t('Last name'));
$form['email'] = array('#type' => 'email', '#title' => $this->t('Email'));
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Submit'), '#button_type' => 'primary');
return $form;
}
示例6: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$installModules = [];
foreach ($form_state->getValues() as $key => $value) {
if (strpos($key, 'install_modules') !== FALSE && $value) {
preg_match('/install_modules_(?P<name>\\w+)/', $key, $values);
$installModules[] = $values['name'];
}
}
$buildInfo = $form_state->getBuildInfo();
$install_state = $buildInfo['args'];
$install_state[0]['thunder_additional_modules'] = $installModules;
$install_state[0]['form_state_values'] = $form_state->getValues();
$buildInfo['args'] = $install_state;
$form_state->setBuildInfo($buildInfo);
}
示例7: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$bi = $form_state->getBuildInfo();
$options = $bi['args'][0];
if (count($options) <= 1) {
return $form;
}
$default = NULL;
if (!empty($_GET['graph'])) {
if (is_string($_GET['graph']) && isset($options[$_GET['graph']])) {
$default = $_GET['graph'];
}
}
$form['graph'] = ['#type' => 'select', '#title' => $this->t('Graph'), '#options' => $options, '#default_value' => $default, '#description' => $this->t('The graph to load the entity from.')];
$form['submit'] = ['#value' => $this->t('Select graph'), '#type' => 'submit'];
$form['#method'] = 'get';
return $form;
}
示例8: submitForm
public function submitForm(array &$form, FormStateInterface $form_state) {
$build_info = $form_state->getBuildInfo();
$build_info['args'][0]['parameters']['langcode'] = $form_state->getValue('langcode');
$build_info['args'][0]['parameters']['langcodes'] = $form_state->getValue('langcodes');
$form_state->setBuildInfo($build_info);
}
示例9: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$build_info = $form_state->getBuildInfo();
$signup = $build_info['callback_object']->signup;
// For forms that allow subscribing to multiple lists
// ensure at least one list is checked.
if (count($signup->mc_lists) > 1) {
$values = $form_state->getValues();
foreach ($values['mailchimp_lists'] as $list) {
if ($list['subscribe']) {
return;
}
}
$form_state->setErrorByName('mailchimp_lists', t("Please select at least one list to subscribe to."));
}
}
示例10: getBuildInfo
/**
* {@inheritdoc}
*/
public function getBuildInfo()
{
return $this->decoratedFormState->getBuildInfo();
}
示例11: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$build_info = $form_state->getBuildInfo();
$account = $build_info['args'][0];
$edit = $form_state->getValues();
// Check out if any downloads were modified.
if (isset($edit['file_download'])) {
foreach ((array) $edit['file_download'] as $fid => $download_modification) {
// Remove this user download?
if ($download_modification['remove']) {
uc_file_remove_user_file_by_id($account, $fid);
} else {
// Calculate the new expiration.
$download_modification['expiration'] = _uc_file_expiration_date($download_modification, $download_modification['expiration']);
// Don't touch anything if everything's the same.
if ($download_modification['download_limit'] == $download_modification['download_limit_old'] && $download_modification['address_limit'] == $download_modification['address_limit_old'] && $download_modification['expiration'] == $download_modification['expiration_old']) {
continue;
}
// Renew. (Explicit overwrite.)
uc_file_user_renew($fid, $account, NULL, $download_modification, TRUE);
}
}
}
// Check out if any downloads were added. We pass NULL to file_user_renew,
// because this shouldn't be associated with a random product.
if (isset($edit['file_add'])) {
$file_config = $this->config('uc_file.settings');
foreach ((array) $edit['file_add'] as $fid => $data) {
$download_modification['download_limit'] = $file_config->get('download_limit_number');
$download_modification['address_limit'] = $file_config->get('download_limit_addresses');
$download_modification['expiration'] = _uc_file_expiration_date(array('time_polarity' => '+', 'time_quantity' => $file_config->get('download_limit_duration_qty'), 'time_granularity' => $file_config->get('download_limit_duration_granularity')), REQUEST_TIME);
// Renew. (Explicit overwrite.)
uc_file_user_renew($fid, $account, NULL, $download_modification, TRUE);
}
}
}
示例12: blockForm
/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state)
{
// Fish the page object from the form args.
// Prevent serialization error.
$form['admin_label']['#markup'] = (string) $form['admin_label']['#markup'];
foreach ($form_state->getBuildInfo()['args'] as $arg) {
if ($arg instanceof Page) {
$this->page = $arg->getExecutable();
}
}
$block_plugins = \Drupal::service('plugin.manager.block')->getDefinitionsForContexts($this->getContexts());
$block_options = array();
foreach ($block_plugins as $plugin_id => $block_definition) {
$block_options[(string) $block_definition['category']][$plugin_id] = (string) $block_definition['admin_label'];
}
$widget_blocks = $form_state->hasValue(array('settings', 'blocks')) ? $form_state->getValue(array('settings', 'blocks')) : $this->configuration['blocks'];
$layout = $form_state->hasValue(array('settings', 'layout')) ? $form_state->getValue(array('settings', 'layout')) : $this->configuration['layout'];
$classes = $form_state->hasValue(array('settings', 'classes')) ? $form_state->getValue(array('settings', 'classes')) : $this->configuration['classes'];
$ajax_properties = array('#ajax' => array('callback' => array($this, 'widgetBlockAJAXCallback'), 'wrapper' => 'widget-block-wrapper', 'effect' => 'fade'));
$form = parent::blockForm($form, $form_state);
$layouts = array();
foreach (Layout::layoutPluginManager()->getDefinitions() as $id => $definition) {
if ($definition['type'] == 'partial') {
$layouts[$id] = $definition['label'];
}
}
$form['layout'] = array('#type' => 'select', '#required' => TRUE, '#title' => t('Widget layout'), '#options' => $layouts, '#default_value' => $layout) + $ajax_properties;
$form['blocks'] = array('#type' => 'container', '#prefix' => '<div id="widget-block-wrapper">', '#suffix' => '</div>');
$form['classes'] = array('#type' => 'textfield', '#title' => t('CSS Classes'), '#default_value' => $classes);
if (!$layout) {
return $form;
}
if ($layout != $this->configuration['layout']) {
$this->configuration['layout'] = $layout;
$this->configuration['regions'] = NULL;
$this->layoutRegionBag = NULL;
}
foreach ($this->getLayoutRegions() as $region_id => $region_definition) {
$block_config = isset($widget_blocks[$region_id]) ? $widget_blocks[$region_id] : array();
$form['blocks'][$region_id] = array('#type' => 'details', '#title' => $region_definition->getConfiguration()['label'], '#open' => TRUE);
$form['blocks'][$region_id]['id'] = array('#type' => 'select', '#title' => t('Block'), '#options' => $block_options, '#default_value' => isset($block_config['id']) ? $block_config['id'] : NULL, '#empty_option' => t('- None -')) + $ajax_properties;
$form['blocks'][$region_id]['region'] = array('#type' => 'value', '#value' => $region_id);
if (!empty($block_config['id'])) {
$block_plugin = \Drupal::service('plugin.manager.block')->createInstance($block_config['id'], $block_config);
$form['blocks'][$region_id] += $block_plugin->buildConfigurationForm(array(), $form_state);
if ($block_plugin instanceof ContextAwarePluginInterface) {
$form['blocks'][$region_id]['context_mapping'] = $this->addContextAssignmentElement($block_plugin, $this->getContexts());
}
// @todo Support per-block caching and visibility. Breaks UI right now.
unset($form['blocks'][$region_id]['cache']);
unset($form['blocks'][$region_id]['visibility']);
unset($form['blocks'][$region_id]['visibility_tabs']);
} else {
//unset($form['blocks'][$region_id]);
}
}
return $form;
}
示例13: submitForm
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->_move_all_config_files_directory('general');
$this->_move_all_config_files_directory('seven');
$this->_move_all_config_files_directory('bfc_admin_theme');
$this->_move_all_config_files_directory('bootstrap');
$this->_move_all_config_files_directory('text_formats_editors');
$this->_move_all_config_files_directory('user');
$this->_move_all_config_files_directory('linkit');
if(!empty($_GET['langcodes'])){
# Enabled multilanguage modules
$this->_move_all_config_files_directory('multilanguage');
}
if ($form_state->getValue('editor') == 1) {
$this->_move_config_file('user.role.editor.yml', 'roles');
}
if ($form_state->getValue('administrator') == 1) {
$this->_move_config_file('user.role.administrator.yml', 'roles');
}
if ($form_state->getValue('article') == 1) {
$this->_move_all_config_files_directory('article');
}
if ($form_state->getValue('page') == 1) {
$this->_move_all_config_files_directory('page');
}
$build_info = $form_state->getBuildInfo();
$build_info['args'][0]['parameters']['configuration'] = TRUE;
$form_state->setBuildInfo($build_info);
}
示例14: getBuildInfo
/**
* {@inheritdoc}
*/
public function getBuildInfo()
{
return $this->mainFormState->getBuildInfo();
}
示例15: prepareForm
/**
* {@inheritdoc}
*/
public function prepareForm($form_id, &$form, FormStateInterface &$form_state)
{
$user = $this->currentUser();
$form['#type'] = 'form';
// Only update the action if it is not already set.
if (!isset($form['#action'])) {
$form['#action'] = $this->buildFormAction();
}
// Fix the form method, if it is 'get' in $form_state, but not in $form.
if ($form_state->isMethodType('get') && !isset($form['#method'])) {
$form['#method'] = 'get';
}
// Generate a new #build_id for this form, if none has been set already.
// The form_build_id is used as key to cache a particular build of the form.
// For multi-step forms, this allows the user to go back to an earlier
// build, make changes, and re-submit.
// @see self::buildForm()
// @see self::rebuildForm()
if (!isset($form['#build_id'])) {
$form['#build_id'] = 'form-' . Crypt::randomBytesBase64();
}
$form['form_build_id'] = array('#type' => 'hidden', '#value' => $form['#build_id'], '#id' => $form['#build_id'], '#name' => 'form_build_id', '#parents' => array('form_build_id'));
// Add a token, based on either #token or form_id, to any form displayed to
// authenticated users. This ensures that any submitted form was actually
// requested previously by the user and protects against cross site request
// forgeries.
// This does not apply to programmatically submitted forms. Furthermore,
// since tokens are session-bound and forms displayed to anonymous users are
// very likely cached, we cannot assign a token for them.
// During installation, there is no $user yet.
if ($user && $user->isAuthenticated() && !$form_state->isProgrammed()) {
// Form constructors may explicitly set #token to FALSE when cross site
// request forgery is irrelevant to the form, such as search forms.
if (isset($form['#token']) && $form['#token'] === FALSE) {
unset($form['#token']);
} else {
$form['#token'] = $form_id;
$form['form_token'] = array('#id' => Html::getUniqueId('edit-' . $form_id . '-form-token'), '#type' => 'token', '#default_value' => $this->csrfToken->get($form['#token']), '#parents' => array('form_token'));
}
}
if (isset($form_id)) {
$form['form_id'] = array('#type' => 'hidden', '#value' => $form_id, '#id' => Html::getUniqueId("edit-{$form_id}"), '#parents' => array('form_id'));
}
if (!isset($form['#id'])) {
$form['#id'] = Html::getUniqueId($form_id);
// Provide a selector usable by JavaScript. As the ID is unique, its not
// possible to rely on it in JavaScript.
$form['#attributes']['data-drupal-selector'] = Html::getId($form_id);
}
$form += $this->elementInfo->getInfo('form');
$form += array('#tree' => FALSE, '#parents' => array());
$form['#validate'][] = '::validateForm';
$form['#submit'][] = '::submitForm';
$build_info = $form_state->getBuildInfo();
// If no #theme has been set, automatically apply theme suggestions.
// The form theme hook itself, which is rendered by form.html.twig,
// is in #theme_wrappers. Therefore, the #theme function only has to care
// for rendering the inner form elements, not the form itself.
if (!isset($form['#theme'])) {
$form['#theme'] = array($form_id);
if (isset($build_info['base_form_id'])) {
$form['#theme'][] = $build_info['base_form_id'];
}
}
// Invoke hook_form_alter(), hook_form_BASE_FORM_ID_alter(), and
// hook_form_FORM_ID_alter() implementations.
$hooks = array('form');
if (isset($build_info['base_form_id'])) {
$hooks[] = 'form_' . $build_info['base_form_id'];
}
$hooks[] = 'form_' . $form_id;
$this->moduleHandler->alter($hooks, $form, $form_state, $form_id);
$this->themeManager->alter($hooks, $form, $form_state, $form_id);
}