/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { if ($form_state->getTriggeringElement()['#name'] == 'select_id_submit') { $form_state->set('default_type', $form_state->getValue('id')); $form_state->setRebuild(); } else { parent::submitForm($form, $form_state); } }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); /** @var \Drupal\commerce_tax\Entity\TaxTypeInterface $tax_type */ $tax_type = $this->entity; /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $zone_storage */ $zone_storage = $this->entityTypeManager->getStorage('zone'); $zones = $zone_storage->loadMultipleOverrideFree(); // @todo Filter by zone scope == 'tax'. $zones = array_map(function ($zone) { return $zone->label(); }, $zones); $form['name'] = ['#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $tax_type->getName(), '#maxlength' => 255, '#required' => TRUE]; $form['id'] = ['#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $tax_type->getId(), '#machine_name' => ['exists' => '\\Drupal\\commerce_tax\\Entity\\TaxType::load', 'source' => ['name']], '#required' => TRUE, '#disabled' => !$tax_type->isNew()]; $form['zone'] = ['#type' => 'select', '#title' => $this->t('Zone'), '#default_value' => $tax_type->getZoneId(), '#options' => $zones, '#required' => TRUE]; if ($tax_type->isNew()) { $link = Link::createFromRoute('Zones page', 'entity.zone.collection')->toString(); $form['zone']['#description'] = $this->t('To add a new zone visit the @link.', ['@link' => $link]); } $form['compound'] = ['#type' => 'checkbox', '#title' => $this->t('Compound'), '#description' => $this->t("Compound tax is calculated on top of a primary tax. For example, Canada's Provincial Sales Tax (PST) is compound, calculated on a price that already includes the Goods and Services Tax (GST)."), '#default_value' => $tax_type->isCompound()]; $form['displayInclusive'] = ['#type' => 'checkbox', '#title' => $this->t('Display inclusive'), '#default_value' => $tax_type->isDisplayInclusive()]; $form['roundingMode'] = ['#type' => 'radios', '#title' => $this->t('Rounding mode'), '#default_value' => $tax_type->getRoundingMode() ?: TaxType::ROUND_HALF_UP, '#options' => [TaxType::ROUND_HALF_UP => $this->t('Round up'), TaxType::ROUND_HALF_DOWN => $this->t('Round down'), TaxType::ROUND_HALF_EVEN => $this->t('Round even'), TaxType::ROUND_HALF_ODD => $this->t('Round odd')], '#required' => TRUE]; $form['tag'] = ['#type' => 'textfield', '#title' => $this->t('Tag'), '#description' => $this->t('Used by the resolvers to analyze only the tax types relevant to them. For example, the EuTaxTypeResolver would analyze only the tax types with the "EU" tag.'), '#default_value' => $tax_type->getTag()]; return $form; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $domain = $this->entity; $domains = \Drupal::service('domain.loader')->loadMultiple(); // Create defaults if this is the first domain. if (empty($domains)) { $domain->addProperty('hostname', \Drupal::service('domain.creator')->createHostname()); $domain->addProperty('name', \Drupal::config('system.site')->get('name')); } $form['domain_id'] = array('#type' => 'value', '#value' => $domain->getDomainId()); $form['hostname'] = array('#type' => 'textfield', '#title' => $this->t('Hostname'), '#size' => 40, '#maxlength' => 80, '#default_value' => $domain->getHostname(), '#description' => $this->t('The canonical hostname, using the full <em>subdomain.example.com</em> format. Leave off the http:// and the trailing slash and do not include any paths.<br />If this domain uses a custom http(s) port, you should specify it here, e.g.: <em>subdomain.example.com:1234</em><br />The hostname may contain only lowercase alphanumeric characters, dots, dashes, and a colon (if using alternative ports).')); $form['id'] = array('#type' => 'machine_name', '#default_value' => $domain->id(), '#machine_name' => array('source' => array('hostname'), 'exists' => '\\Drupal\\domain\\Entity\\Domain::load')); $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#size' => 40, '#maxlength' => 80, '#default_value' => $domain->label(), '#description' => $this->t('The human-readable name is shown in domain lists and may be used as the title tag.')); // Do not use the :// suffix when storing data. $add_suffix = FALSE; $form['scheme'] = array('#type' => 'radios', '#title' => $this->t('Domain URL scheme'), '#options' => array('http' => 'http://', 'https' => 'https://'), '#default_value' => $domain->getScheme($add_suffix), '#description' => $this->t('This URL scheme will be used when writing links and redirects to this domain and its resources.')); $form['status'] = array('#type' => 'radios', '#title' => $this->t('Domain status'), '#options' => array(1 => $this->t('Active'), 0 => $this->t('Inactive')), '#default_value' => (int) $domain->status(), '#description' => $this->t('"Inactive" domains are only accessible to user roles with that assigned permission.')); $form['weight'] = array('#type' => 'weight', '#title' => $this->t('Weight'), '#delta' => count(\Drupal::service('domain.loader')->loadMultiple()) + 1, '#default_value' => $domain->getWeight(), '#description' => $this->t('The sort order for this record. Lower values display first.')); $form['is_default'] = array('#type' => 'checkbox', '#title' => $this->t('Default domain'), '#default_value' => $domain->isDefault(), '#description' => $this->t('If a URL request fails to match a domain record, the settings for this domain will be used. Only one domain can be default.')); $required = \Drupal::service('domain.validator')->getRequiredFields(); foreach ($form as $key => $element) { if (in_array($key, $required)) { $form[$key]['#required'] = TRUE; } } return $form; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $vocabulary = $this->entity; if ($vocabulary->isNew()) { $form['#title'] = $this->t('Add vocabulary'); } else { $form['#title'] = $this->t('Edit vocabulary'); } $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $vocabulary->label(), '#maxlength' => 255, '#required' => TRUE); $form['vid'] = array('#type' => 'machine_name', '#default_value' => $vocabulary->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array('exists' => array($this, 'exists'), 'source' => array('name'))); $form['description'] = array('#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $vocabulary->getDescription()); // $form['langcode'] is not wrapped in an // if ($this->moduleHandler->moduleExists('language')) check because the // language_select form element works also without the language module being // installed. https://www.drupal.org/node/1749954 documents the new element. $form['langcode'] = array('#type' => 'language_select', '#title' => $this->t('Vocabulary language'), '#languages' => LanguageInterface::STATE_ALL, '#default_value' => $vocabulary->language()->getId()); if ($this->moduleHandler->moduleExists('language')) { $form['default_terms_language'] = array('#type' => 'details', '#title' => $this->t('Terms language'), '#open' => TRUE); $form['default_terms_language']['default_language'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'taxonomy_term', 'bundle' => $vocabulary->id()), '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary->id())); } // Set the hierarchy to "multiple parents" by default. This simplifies the // vocabulary form and standardizes the term form. $form['hierarchy'] = array('#type' => 'value', '#value' => '0'); return parent::form($form, $form_state, $vocabulary); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // Get an array of strings with the permissions names. $permissions = array_keys(array_filter($form_state->getValue('permissions'))); $form_state->setValue('permissions', $permissions); parent::submitForm($form, $form_state); }
/** * {@inheritdoc} */ public function buildEntity(array $form, FormStateInterface $form_state) { $entity = parent::buildEntity($form, $form_state); $tags = array_map('trim', explode(',', $entity->get('tags'))); $entity->set('tags', $tags); return $entity; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); /** @var \Drupal\rng\EventTypeInterface $event_type */ $event_type = $this->entity; if (!$event_type->isNew()) { $form['#title'] = $this->t('Edit event type %label configuration', array('%label' => $event_type->label())); } if ($event_type->isNew()) { $bundle_options = []; // Generate a list of fieldable bundles which are not events. foreach ($this->entityManager->getDefinitions() as $entity_type) { if ($entity_type->isSubclassOf('\\Drupal\\Core\\Entity\\ContentEntityInterface')) { foreach ($this->entityManager->getBundleInfo($entity_type->id()) as $bundle => $bundle_info) { if (!$this->eventManager->eventType($entity_type->id(), $bundle)) { $bundle_options[(string) $entity_type->getLabel()][$entity_type->id() . '.' . $bundle] = $bundle_info['label']; } } } } if ($this->moduleHandler->moduleExists('node')) { $form['#attached']['library'][] = 'rng/rng.admin'; $form['entity_type'] = ['#type' => 'radios', '#options' => NULL, '#title' => $this->t('Event entity type'), '#required' => TRUE]; $form['entity_type']['node']['radio'] = ['#type' => 'radio', '#title' => $this->t('Create a new content type'), '#description' => $this->t('Create a content type to use as an event type.'), '#return_value' => "node", '#parents' => array('entity_type'), '#default_value' => 'node']; $form['entity_type']['existing']['radio'] = ['#type' => 'radio', '#title' => $this->t('Use existing bundle'), '#description' => $this->t('Use an existing entity/bundle combination.'), '#return_value' => "existing", '#parents' => array('entity_type'), '#default_value' => '']; $form['entity_type']['existing']['container'] = ['#type' => 'container', '#attributes' => ['class' => ['rng-radio-indent']]]; } $form['entity_type']['existing']['container']['bundle'] = array('#type' => 'select', '#title' => $this->t('Bundle'), '#options' => $bundle_options, '#default_value' => $event_type->id(), '#disabled' => !$event_type->isNew(), '#empty_option' => $bundle_options ? NULL : t('No Bundles Available')); } $form['settings'] = array('#type' => 'fieldset', '#title' => $this->t('Settings')); // Mirror permission. $form['access']['mirror_update'] = array('#group' => 'settings', '#type' => 'checkbox', '#title' => t('Mirror manage registrations with update permission'), '#description' => t('Allow users to <strong>manage registrations</strong> if they have <strong>update</strong> permission on an event entity.'), '#default_value' => (bool) ($event_type->getEventManageOperation() !== NULL ? $event_type->getEventManageOperation() : TRUE)); return $form; }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { if ($form_state->getValue('stateFrom') === $form_state->getValue('stateTo')) { $form_state->setErrorByName('stateTo', $this->t('You cannot use the same state for both from and to.')); } parent::validateForm($form, $form_state); }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#description' => $this->t('The label for this page.'), '#default_value' => $this->entity->label(), '#required' => TRUE, '#maxlength' => '255']; $form['id'] = ['#type' => 'machine_name', '#default_value' => $this->entity->id(), '#disabled' => !$this->entity->isNew(), '#maxlength' => 64, '#required' => TRUE, '#machine_name' => ['exists' => [$this, 'exists']]]; $form['path'] = ['#type' => 'textfield', '#title' => $this->t('Path'), '#maxlength' => 255, '#default_value' => $this->entity->getPath(), '#required' => TRUE, '#element_validate' => [[$this, 'validatePath']]]; return parent::form($form, $form_state); }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form['label'] = [ '#type' => 'textfield', '#title' => $this->t('Profile Name'), '#default_value' => $this->entity->label(), '#description' => $this->t('The human-readable name of this profile. This name must be unique.'), '#required' => TRUE, '#size' => 30, ]; $form['id'] = [ '#type' => 'machine_name', '#default_value' => $this->entity->id(), '#machine_name' => [ 'exists' => ['\Drupal\linkit\Entity\Profile', 'load'] ], '#disabled' => !$this->entity->isNew(), ]; $form['description'] = [ '#type' => 'textarea', '#title' => $this->t('Description'), '#default_value' => $this->entity->getDescription(), '#description' => $this->t('The text will be displayed on the <em>profile collection</em> page.'), ]; $form['additional_settings'] = array( '#type' => 'vertical_tabs', '#weight' => 99, ); return parent::form($form, $form_state); }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { $actions = parent::actions($form, $form_state); $actions['submit']['#value'] = $this->t('Save activity type'); $actions['delete']['#title'] = $this->t('Delete activity type'); return $actions; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $keys = $this->key_repository->getKeys(); if (empty($keys)) { drupal_set_message('No system keys (admin/config/system/key) are installed to manage encryption profiles.'); } /** @var $encryption_profile \Drupal\encrypt\Entity\EncryptionProfile */ $encryption_profile = $this->entity; $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $encryption_profile->label(), '#description' => $this->t("Label for the encryption profile."), '#required' => TRUE); $form['id'] = array('#type' => 'machine_name', '#default_value' => $encryption_profile->id(), '#machine_name' => array('exists' => '\\Drupal\\encrypt\\Entity\\EncryptionProfile::load'), '#disabled' => !$encryption_profile->isNew()); /** @var $key \Drupal\key\Entity\KeyInterface */ foreach ($keys as $key) { $key_id = $key->id(); $key_title = $key->label(); $keys[$key_id] = (string) $key_title; } if ($profile_key = $encryption_profile->getEncryptionKey()) { $default_key = $profile_key; } $form['encryption_key'] = array('#type' => 'select', '#title' => $this->t('Encryption Key'), '#description' => $this->t('Select the key used for encryption.'), '#options' => $keys, '#default_value' => empty($default_key) ? NULL : $default_key, '#required' => TRUE); $enc_methods = []; foreach ($this->encrypt_service->loadEncryptionMethods() as $plugin_id => $definition) { $enc_methods[$plugin_id] = (string) $definition['title']; } $form['encryption_method'] = array('#type' => 'select', '#title' => $this->t('Encryption Method'), '#description' => $this->t('Select the method used for encryption'), '#options' => $enc_methods, '#default_value' => $encryption_profile->getEncryptionMethod()); return $form; }
/** * Overrides Drupal\Core\Entity\EntityForm::form(). * * @param array $form * A nested array form elements comprising the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param \Drupal\responsive_image\ResponsiveImageMappingInterface $responsive_image_mapping * The entity being edited. * * @return array * The array containing the complete form. */ public function form(array $form, FormStateInterface $form_state) { if ($this->operation == 'duplicate') { $form['#title'] = $this->t('<em>Duplicate responsive image mapping</em> @label', array('@label' => $this->entity->label())); $this->entity = $this->entity->createDuplicate(); } if ($this->operation == 'edit') { $form['#title'] = $this->t('<em>Edit responsive image mapping</em> @label', array('@label' => $this->entity->label())); } /** @var \Drupal\responsive_image\ResponsiveImageMappingInterface $responsive_image_mapping */ $responsive_image_mapping = $this->entity; $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $responsive_image_mapping->label(), '#description' => $this->t("Example: 'Hero image' or 'Author image'."), '#required' => TRUE); $form['id'] = array('#type' => 'machine_name', '#default_value' => $responsive_image_mapping->id(), '#machine_name' => array('exists' => '\\Drupal\\responsive_image\\Entity\\ResponsiveImageMapping::load', 'source' => array('label')), '#disabled' => (bool) $responsive_image_mapping->id() && $this->operation != 'duplicate'); if ((bool) $responsive_image_mapping->id() && $this->operation != 'duplicate') { $description = $this->t('Select a breakpoint group from the enabled themes.') . ' ' . $this->t("Warning: if you change the breakpoint group you lose all your selected mappings."); } else { $description = $this->t('Select a breakpoint group from the enabled themes.'); } $form['breakpointGroup'] = array('#type' => 'select', '#title' => $this->t('Breakpoint group'), '#default_value' => $responsive_image_mapping->getBreakpointGroup() != '' ? $responsive_image_mapping->getBreakpointGroup()->id() : '', '#options' => breakpoint_group_select_options(), '#required' => TRUE, '#description' => $description); $image_styles = image_style_options(TRUE); $image_styles[RESPONSIVE_IMAGE_EMPTY_IMAGE] = $this->t('- empty image -'); foreach ($responsive_image_mapping->getMappings() as $breakpoint_id => $mapping) { foreach ($mapping as $multiplier => $image_style) { $breakpoint = $responsive_image_mapping->getBreakpointGroup()->getBreakpointById($breakpoint_id); $label = $multiplier . ' ' . $breakpoint->name . ' [' . $breakpoint->mediaQuery . ']'; $form['mappings'][$breakpoint_id][$multiplier] = array('#type' => 'select', '#title' => String::checkPlain($label), '#options' => $image_styles, '#default_value' => $image_style, '#description' => $this->t('Select an image style for this breakpoint.')); } } $form['#tree'] = TRUE; return parent::form($form, $form_state, $responsive_image_mapping); }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $menu_block = $this->entity; // Label field. $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Administrative Label'), '#maxlength' => 255, '#default_value' => $menu_block->label(), '#required' => TRUE); // ID field. $form['id'] = array('#type' => 'machine_name', '#default_value' => $menu_block->id(), '#machine_name' => array('exists' => '\\Drupal\\menu_block\\Entity\\MenuBlock::load'), '#disabled' => !$menu_block->isNew()); // Menu selection. $options = []; $menu_storage = \Drupal::entityManager()->getStorage('menu'); foreach ($menu_storage->loadMultiple() as $menu) { $options[$menu->id()] = $menu->label(); } $form['menu'] = ['#type' => 'select', '#title' => $this->t('Menu'), '#options' => $options, '#default_value' => $menu_block->getMenu()]; // Block title. $form['block_title'] = array('#type' => 'textfield', '#title' => $this->t('Block Title'), '#maxlength' => 255, '#default_value' => $menu_block->getBlockTitle()); // Administrative block title. $form['admin_block_title'] = array('#type' => 'textfield', '#title' => $this->t('Administrative Block Title'), '#maxlength' => 255, '#default_value' => $menu_block->getAdminBlockTitle(), '#required' => TRUE); // Starting level. // TODO - Look at AJAX based on menu selected $form['starting_level'] = array('#type' => 'select', '#title' => $this->t('Starting Menu Level'), '#maxlength' => 255, '#default_value' => $menu_block->getStartingLevel(), '#options' => array('0' => 'Root', '1' => 'Level 1', '2' => 'Level 2', '3' => 'Level 3', '4' => 'Level 4', '5' => 'Level 5', '6' => 'Level 6', '7' => 'Level 7', '8' => 'Level 8'), '#required' => TRUE, '#description' => $this->t("Select which level of the menu the menu block begins.")); // Maximum depth. $form['maximum_depth'] = array('#type' => 'select', '#title' => $this->t('Starting Menu Level'), '#maxlength' => 255, '#default_value' => $menu_block->getMaximumDepth(), '#options' => array('0' => 'All levels', '1' => '1 level', '2' => '2 levels', '3' => '3 levels', '4' => '4 levels', '5' => '5 levels', '6' => '6 levels', '7' => '7 levels', '8' => '8 levels'), '#required' => TRUE, '#description' => $this->t("Select how many levels of the menu block should render.")); return $form; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $entity = $this->entity; $form['label'] = array('#type' => 'textfield', '#title' => 'Label', '#default_value' => $entity->label(), '#required' => TRUE); $form['id'] = array('#type' => 'machine_name', '#default_value' => $entity->id(), '#required' => TRUE, '#machine_name' => array('exists' => [$this, 'exists'], 'replace_pattern' => '[^a-z0-9_.]+')); $form['weight'] = array('#type' => 'weight', '#title' => 'Weight', '#default_value' => $entity->get('weight')); $form['style'] = array('#type' => 'select', '#title' => 'Image style', '#options' => array(), '#default_value' => $entity->get('style'), '#access' => FALSE); if ($this->moduleHandler->moduleExists('image')) { $form['style']['#access'] = TRUE; $form['style']['#options'] = image_style_options(); } // The main premise of entity forms is that we get to work with an entity // object at all times instead of checking submitted values from the form // state. $size = $entity->get('size'); $form['size_wrapper'] = array('#type' => 'container', '#attributes' => array('id' => 'size-wrapper')); $form['size_wrapper']['size'] = array('#type' => 'select', '#title' => 'Size', '#options' => array('custom' => 'Custom'), '#empty_option' => '- None -', '#default_value' => $size, '#ajax' => array('callback' => '::updateSize', 'wrapper' => 'size-wrapper')); $form['size_wrapper']['size_submit'] = array('#type' => 'submit', '#value' => t('Change size'), '#attributes' => array('class' => array('js-hide')), '#submit' => array(array(get_class($this), 'changeSize'))); $form['size_wrapper']['size_value'] = array('#type' => 'select', '#title' => 'Custom size value', '#options' => array('small' => 'Small', 'medium' => 'Medium', 'large' => 'Large'), '#default_value' => $entity->get('size_value'), '#access' => !empty($size)); $form['langcode'] = array('#type' => 'language_select', '#title' => t('Language'), '#languages' => LanguageInterface::STATE_ALL, '#default_value' => $entity->language()->getId()); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Save'); $form['actions']['delete'] = array('#type' => 'submit', '#value' => 'Delete'); return $form; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $comment_type = $this->entity; $form['label'] = array('#type' => 'textfield', '#title' => t('Label'), '#maxlength' => 255, '#default_value' => $comment_type->label(), '#required' => TRUE); $form['id'] = array('#type' => 'machine_name', '#default_value' => $comment_type->id(), '#machine_name' => array('exists' => '\\Drupal\\comment\\Entity\\CommentType::load'), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => !$comment_type->isNew()); $form['description'] = array('#type' => 'textarea', '#default_value' => $comment_type->getDescription(), '#description' => t('Describe this comment type. The text will be displayed on the <em>Comment types</em> administration overview page.'), '#title' => t('Description')); if ($comment_type->isNew()) { $options = array(); foreach ($this->entityManager->getDefinitions() as $entity_type) { // Only expose entities that have field UI enabled, only those can // get comment fields added in the UI. if ($entity_type->get('field_ui_base_route')) { $options[$entity_type->id()] = $entity_type->getLabel(); } } $form['target_entity_type_id'] = array('#type' => 'select', '#default_value' => $comment_type->getTargetEntityTypeId(), '#title' => t('Target entity type'), '#options' => $options, '#description' => t('The target entity type can not be changed after the comment type has been created.')); } else { $form['target_entity_type_id_display'] = array('#type' => 'item', '#markup' => $this->entityManager->getDefinition($comment_type->getTargetEntityTypeId())->getLabel(), '#title' => t('Target entity type')); } if ($this->moduleHandler->moduleExists('content_translation')) { $form['language'] = array('#type' => 'details', '#title' => t('Language settings'), '#group' => 'additional_settings'); $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('comment', $comment_type->id()); $form['language']['language_configuration'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'comment', 'bundle' => $comment_type->id()), '#default_value' => $language_configuration); $form['#submit'][] = 'language_configuration_element_submit'; } $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save')); return $form; }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { $actions = parent::actions($form, $form_state); if ($this->entity->isNew()) { $actions['submit']['#value'] = $this->t('Save and edit'); } return $actions; }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { // Get the basic actions from the base class. $actions = parent::actions($form, $form_state); // Change the submit button text. $actions['submit']['#value'] = $this->t('Save'); return $actions; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $display_id = NULL) { if (isset($display_id) && $form_state->has('display_id') && $display_id !== $form_state->get('display_id')) { throw new \InvalidArgumentException('Mismatch between $form_state->get(\'display_id\') and $display_id.'); } $this->displayID = $form_state->has('display_id') ? $form_state->get('display_id') : $display_id; return parent::buildForm($form, $form_state); }
/** * {@inheritdoc} */ public function form(array $form, array &$form_state) { $entity = $this->entity; $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Role name'), '#default_value' => $entity->label(), '#size' => 30, '#required' => TRUE, '#maxlength' => 64, '#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".')); $form['id'] = array('#type' => 'machine_name', '#default_value' => $entity->id(), '#required' => TRUE, '#disabled' => !$entity->isNew(), '#size' => 30, '#maxlength' => 64, '#machine_name' => array('exists' => 'user_role_load')); $form['weight'] = array('#type' => 'value', '#value' => $entity->getWeight()); return parent::form($form, $form_state, $entity); }
/** * {@inheritdoc} */ public function buildEntity(array $form, FormStateInterface $form_state) { // Save period. $type = Schedule::getPeriodType($form_state->getValue('period_type')); $seconds = Schedule::periodToSeconds(['number' => $form_state->getValue('period_number'), 'type' => $type]); $form_state->setValue('period', $seconds); return parent::buildEntity($form, $form_state); }
/** * {@inheritdoc} */ public function validate(array $form, FormStateInterface $form_state) { parent::validate($form, $form_state); $entity = $this->entity; // Check to prevent a duplicate title. if ($form_state['values']['label'] != $entity->label() && shortcut_set_title_exists($form_state['values']['label'])) { $form_state->setErrorByName('label', $this->t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['label']))); } }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $currency = $this->entity; $form['name'] = [ '#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $currency->getName(), '#maxlength' => 255, '#required' => TRUE, ]; $form['currencyCode'] = [ '#type' => 'textfield', '#title' => $this->t('Currency code'), '#default_value' => $currency->getCurrencyCode(), '#element_validate' => ['::validateCurrencyCode'], '#pattern' => '[A-Z]{3}', '#placeholder' => 'XXX', '#maxlength' => 3, '#size' => 3, '#disabled' => !$currency->isNew(), '#required' => TRUE, ]; $form['numericCode'] = [ '#type' => 'textfield', '#title' => $this->t('Numeric code'), '#default_value' => $currency->getNumericCode(), '#element_validate' => ['::validateNumericCode'], '#pattern' => '[\d]{3}', '#placeholder' => '999', '#maxlength' => 3, '#size' => 3, '#required' => TRUE, ]; $form['symbol'] = [ '#type' => 'textfield', '#title' => $this->t('Symbol'), '#default_value' => $currency->getSymbol(), '#maxlength' => 255, '#required' => TRUE, ]; $form['fractionDigits'] = [ '#type' => 'number', '#title' => $this->t('Fraction digits'), '#description' => $this->t('The number of digits after the decimal sign.'), '#default_value' => $currency->getFractionDigits() ?: 2, '#min' => 0, '#required' => TRUE, ]; $form['status'] = [ '#type' => 'checkbox', '#title' => $this->t('Enabled'), '#default_value' => $currency->status(), ]; return $form; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $element = parent::form($form, $form_state); $element['label'] = array('#type' => 'textfield', '#title' => t('Name'), '#default_value' => $this->entity->label(), '#maxlength' => 255, '#required' => TRUE); $element['id'] = array('#type' => 'machine_name', '#title' => t('Machine-readable name'), '#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'), '#disabled' => !$this->entity->isNew(), '#default_value' => $this->entity->id(), '#machine_name' => array('exists' => array($this, 'exists'))); $element['pattern'] = array('#type' => 'textfield', '#title' => t('Format'), '#default_value' => $this->entity->get('pattern'), '#maxlength' => 255, '#required' => TRUE); $element['help'] = $this->nameFormatHelp(); return $element; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $default_entity = $this->entity; $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $default_entity->label(), '#description' => $this->t("Label for the Default entity."), '#required' => TRUE); $form['id'] = array('#type' => 'machine_name', '#default_value' => $default_entity->id(), '#machine_name' => array('exists' => '\\Drupal\\unicef42\\Entity\\DefaultEntity::load'), '#disabled' => !$default_entity->isNew()); /* You will need additional form elements for your custom properties. */ return $form; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $entity = $this->entity; $form['label'] = array('#type' => 'textfield', '#title' => t('Set name'), '#description' => t('The new set is created by copying items from your default shortcut set.'), '#required' => TRUE, '#default_value' => $entity->label()); $form['id'] = array('#type' => 'machine_name', '#machine_name' => array('exists' => '\\Drupal\\shortcut\\Entity\\ShortcutSet::load', 'source' => array('label'), 'replace_pattern' => '[^a-z0-9-]+', 'replace' => '-'), '#default_value' => $entity->id(), '#disabled' => !$entity->isNew(), '#maxlength' => 23); $form['actions']['submit']['#value'] = t('Create new set'); return $form; }
/** * {@inheritdoc} */ public function validate(array $form, FormStateInterface $form_state) { parent::validate($form, $form_state); $id = trim($form_state->getValue('type')); // '0' is invalid, since elsewhere we check it using empty(). if ($id == '0') { $form_state->setErrorByName('type', $this->t("Invalid machine-readable name. Enter a name other than %invalid.", array('%invalid' => $id))); } }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { $actions = parent::actions($form, $form_state); $actions['submit']['#value'] = $this->getConfirmText(); unset($actions['delete']); // Prepare cancel link. $actions['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest()); return $actions; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $paragraphs_type = $this->entity; $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $paragraphs_type->label(), '#description' => $this->t("Label for the Paragraphs type."), '#required' => TRUE); $form['id'] = array('#type' => 'machine_name', '#default_value' => $paragraphs_type->id(), '#machine_name' => array('exists' => 'paragraphs_type_load'), '#disabled' => !$paragraphs_type->isNew()); // You will need additional form elements for your custom properties. return $form; }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { $form = parent::actions($form, $form_state); // We want to display the button only on add page. if ($this->entity->isNew() && \Drupal::moduleHandler()->moduleExists('field_ui')) { $form['submit']['#value'] = $this->t('Save and manage fields'); } return $form; }