当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityForm::form方法代码示例

本文整理汇总了PHP中Drupal\Core\Entity\EntityForm::form方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityForm::form方法的具体用法?PHP EntityForm::form怎么用?PHP EntityForm::form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Entity\EntityForm的用法示例。


在下文中一共展示了EntityForm::form方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: form

 /**
  * {@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);
 }
开发者ID:neeravbm,项目名称:unify-d8,代码行数:10,代码来源:PageFormBase.php

示例2: 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);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:28,代码来源:VocabularyForm.php

示例3: form

 /**
  * {@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;
 }
开发者ID:nerdstein,项目名称:menu_block,代码行数:29,代码来源:MenuBlockForm.php

示例4: form

 /**
  * {@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;
 }
开发者ID:juanramonperez,项目名称:encrypt,代码行数:31,代码来源:EncryptionProfileForm.php

示例5: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     /* @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $bundle */
     $bundle = $form_state->getFormObject()->getEntity();
     $form['enable_moderation_state'] = ['#type' => 'checkbox', '#title' => $this->t('Enable moderation states.'), '#description' => $this->t('Content of this type must transition through moderation states in order to be published.'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'enabled', FALSE)];
     // Add a special message when moderation is being disabled.
     if ($bundle->getThirdPartySetting('content_moderation', 'enabled', FALSE)) {
         $form['enable_moderation_state_note'] = ['#type' => 'item', '#description' => $this->t('After disabling moderation, any existing forward drafts will be accessible via the "Revisions" tab.'), '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => FALSE]]]];
     }
     $states = $this->entityTypeManager->getStorage('moderation_state')->loadMultiple();
     $label = function (ModerationState $state) {
         return $state->label();
     };
     $options_published = array_map($label, array_filter($states, function (ModerationState $state) {
         return $state->isPublishedState();
     }));
     $options_unpublished = array_map($label, array_filter($states, function (ModerationState $state) {
         return !$state->isPublishedState();
     }));
     $form['allowed_moderation_states_unpublished'] = ['#type' => 'checkboxes', '#title' => $this->t('Allowed moderation states (Unpublished)'), '#description' => $this->t('The allowed unpublished moderation states this content-type can be assigned.'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'allowed_moderation_states', array_keys($options_unpublished)), '#options' => $options_unpublished, '#required' => TRUE, '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => TRUE]]]];
     $form['allowed_moderation_states_published'] = ['#type' => 'checkboxes', '#title' => $this->t('Allowed moderation states (Published)'), '#description' => $this->t('The allowed published moderation states this content-type can be assigned.'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'allowed_moderation_states', array_keys($options_published)), '#options' => $options_published, '#required' => TRUE, '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => TRUE]]]];
     // The key of the array needs to be a user-facing string so we have to fully
     // render the translatable string to a real string, or else PHP errors on an
     // object used as an array key.
     $options = [$this->t('Unpublished')->render() => $options_unpublished, $this->t('Published')->render() => $options_published];
     $form['default_moderation_state'] = ['#type' => 'select', '#title' => $this->t('Default moderation state'), '#options' => $options, '#description' => $this->t('Select the moderation state for new content'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'default_moderation_state', 'draft'), '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => TRUE]]]];
     $form['#entity_builders'][] = [$this, 'formBuilderCallback'];
     return parent::form($form, $form_state);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:32,代码来源:BundleModerationConfigurationForm.php

示例6: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /* @var \Drupal\crm_core_contact\Entity\ContactType $type */
     $type = $this->entity;
     $form['name'] = array('#title' => $this->t('Name'), '#type' => 'textfield', '#default_value' => $type->name, '#description' => $this->t('The human-readable name of this contact type. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'), '#required' => TRUE, '#size' => 32);
     $form['type'] = array('#type' => 'machine_name', '#default_value' => $type->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array('exists' => 'Drupal\\crm_core_contact\\Entity\\ContactType::load', 'source' => array('name')), '#description' => $this->t('A unique machine-readable name for this contact type. It must only contain lowercase letters, numbers, and underscores.'));
     $form['description'] = array('#title' => $this->t('Description'), '#type' => 'textarea', '#default_value' => $type->description, '#description' => $this->t('Describe this contact type.'));
     // Primary fields section.
     $form['primary_fields_container'] = array('#type' => 'fieldset', '#title' => $this->t('Primary Fields'), '#description' => $this->t('Primary fields are used to tell other modules what fields to use for common communications tasks such as sending an email, addressing an envelope, etc. Use the fields below to indicate the primary fields for this contact type.'));
     // @todo Move primary fields array to some hook. This Would allow extend this
     // list to other modules. This hook should return arra('key'=>t('Name')).
     $default_primary_fields = array('email', 'address', 'phone');
     //    $primary_fields = variable_get('crm_core_contact_default_primary_fields', $default_primary_fields);
     $primary_fields = $default_primary_fields;
     $options = array();
     if (isset($type->type)) {
         /* @var \Drupal\Core\Field\FieldDefinitionInterface[] $instances */
         $instances = \Drupal::entityManager()->getFieldDefinitions('crm_core_contact', $type->type);
         $instances = isset($instances[$type->type]) ? $instances[$type->type] : array();
         foreach ($instances as $instance) {
             $options[$instance->getName()] = $instance->getLabel();
         }
     }
     foreach ($primary_fields as $primary_field) {
         $form['primary_fields_container'][$primary_field] = array('#type' => 'select', '#title' => $this->t('Primary @field field', array('@field' => $primary_field)), '#default_value' => empty($type->primary_fields[$primary_field]) ? '' : $type->primary_fields[$primary_field], '#empty_value' => '', '#empty_option' => $this->t('--Please Select--'), '#options' => $options);
     }
     return $form;
 }
开发者ID:jasonruyle,项目名称:crm_core,代码行数:32,代码来源:ContactTypeForm.php

示例7: form

 /**
  * {@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;
 }
开发者ID:alexburrows,项目名称:cream-2.x,代码行数:28,代码来源:TaxTypeForm.php

示例8: 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);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:44,代码来源:ResponsiveImageMappingForm.php

示例9: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $type = $this->entity;
     if ($this->operation == 'add') {
         $form['#title'] = String::checkPlain($this->t('Add content type'));
     } elseif ($this->operation == 'edit') {
         $form['#title'] = $this->t('Edit %label content type', array('%label' => $type->label()));
     }
     $node_settings = $type->getModuleSettings('node');
     // Prepare node options to be used for 'checkboxes' form element.
     $keys = array_keys(array_filter($node_settings['options']));
     $node_settings['options'] = array_combine($keys, $keys);
     $form['name'] = array('#title' => t('Name'), '#type' => 'textfield', '#default_value' => $type->name, '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the <em>Add content</em> page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'), '#required' => TRUE, '#size' => 30);
     $form['type'] = array('#type' => 'machine_name', '#default_value' => $type->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => $type->isLocked(), '#machine_name' => array('exists' => 'node_type_load', 'source' => array('name')), '#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array('%node-add' => t('Add content'))));
     $form['description'] = array('#title' => t('Description'), '#type' => 'textarea', '#default_value' => $type->description, '#description' => t('Describe this content type. The text will be displayed on the <em>Add content</em> page.'));
     $form['additional_settings'] = array('#type' => 'vertical_tabs', '#attached' => array('library' => array('node/drupal.content_types')));
     $form['submission'] = array('#type' => 'details', '#title' => t('Submission form settings'), '#group' => 'additional_settings', '#open' => TRUE);
     $form['submission']['title_label'] = array('#title' => t('Title field label'), '#type' => 'textfield', '#default_value' => $type->title_label, '#required' => TRUE);
     $form['submission']['preview'] = array('#type' => 'radios', '#title' => t('Preview before submitting'), '#parents' => array('settings', 'node', 'preview'), '#default_value' => $node_settings['preview'], '#options' => array(DRUPAL_DISABLED => t('Disabled'), DRUPAL_OPTIONAL => t('Optional'), DRUPAL_REQUIRED => t('Required')));
     $form['submission']['help'] = array('#type' => 'textarea', '#title' => t('Explanation or submission guidelines'), '#default_value' => $type->help, '#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'));
     $form['workflow'] = array('#type' => 'details', '#title' => t('Publishing options'), '#group' => 'additional_settings');
     $form['workflow']['options'] = array('#type' => 'checkboxes', '#title' => t('Default options'), '#parents' => array('settings', 'node', 'options'), '#default_value' => $node_settings['options'], '#options' => array('status' => t('Published'), 'promote' => t('Promoted to front page'), 'sticky' => t('Sticky at top of lists'), 'revision' => t('Create new revision')), '#description' => t('Users with the <em>Administer content</em> permission will be able to override these options.'));
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = array('#type' => 'details', '#title' => t('Language settings'), '#group' => 'additional_settings');
         $language_configuration = language_get_default_configuration('node', $type->id());
         $form['language']['language_configuration'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'node', 'bundle' => $type->id()), '#default_value' => $language_configuration);
     }
     $form['display'] = array('#type' => 'details', '#title' => t('Display settings'), '#group' => 'additional_settings');
     $form['display']['submitted'] = array('#type' => 'checkbox', '#title' => t('Display author and date information.'), '#parents' => array('settings', 'node', 'submitted'), '#default_value' => $node_settings['submitted'], '#description' => t('Author username and publish date will be displayed.'));
     return $form;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:35,代码来源:NodeTypeForm.php

示例10: 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;
 }
开发者ID:dropdog,项目名称:play,代码行数:31,代码来源:DomainForm.php

示例11: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var \Drupal\embed\EmbedButtonInterface $button */
     $button = $this->entity;
     $form_state->setTemporaryValue('embed_button', $button);
     $form['label'] = ['#title' => $this->t('Label'), '#type' => 'textfield', '#default_value' => $button->label(), '#description' => t('The human-readable name of this embed button. This text will be displayed when the user hovers over the CKEditor button. This name must be unique.'), '#required' => TRUE, '#size' => 30];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $button->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => !$button->isNew(), '#machine_name' => ['exists' => ['Drupal\\embed\\Entity\\EmbedButton', 'load']], '#description' => $this->t('A unique machine-readable name for this embed button. It must only contain lowercase letters, numbers, and underscores.')];
     $form['type_id'] = ['#type' => 'select', '#title' => $this->t('Embed type'), '#options' => $this->embedTypeManager->getDefinitionOptions(), '#default_value' => $button->getTypeId(), '#required' => TRUE, '#ajax' => ['callback' => '::updateTypeSettings', 'effect' => 'fade'], '#disabled' => !$button->isNew()];
     if (count($form['type_id']['#options']) == 0) {
         drupal_set_message($this->t('No embed types found.'), 'warning');
     }
     // Add the embed type plugin settings.
     $form['type_settings'] = ['#type' => 'container', '#tree' => TRUE, '#prefix' => '<div id="embed-type-settings-wrapper">', '#suffix' => '</div>'];
     try {
         if ($plugin = $button->getTypePlugin()) {
             $form['type_settings'] = $plugin->buildConfigurationForm($form['type_settings'], $form_state);
         }
     } catch (PluginNotFoundException $exception) {
         drupal_set_message($exception->getMessage(), 'error');
         watchdog_exception('embed', $exception);
         $form['type_id']['#disabled'] = FALSE;
     }
     $config = $this->config('embed.settings');
     $upload_location = $config->get('file_scheme') . '://' . $config->get('upload_directory') . '/';
     $form['icon_file'] = ['#title' => $this->t('Button icon'), '#type' => 'managed_file', '#description' => $this->t('Icon for the button to be shown in CKEditor toolbar. Leave empty to use the default Entity icon.'), '#upload_location' => $upload_location, '#upload_validators' => ['file_validate_extensions' => ['gif png jpg jpeg'], 'file_validate_image_resolution' => ['32x32', '16x16']]];
     if ($file = $button->getIconFile()) {
         $form['icon_file']['#default_value'] = ['target_id' => $file->id()];
     }
     return $form;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:34,代码来源:EmbedButtonForm.php

示例12: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var ScheduledUpdateType $scheduled_update_type */
     $scheduled_update_type = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $scheduled_update_type->label(), '#description' => $this->t("Label for the Scheduled update type."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $scheduled_update_type->id(), '#machine_name' => array('exists' => '\\Drupal\\scheduled_updates\\Entity\\ScheduledUpdateType::load'), '#disabled' => !$scheduled_update_type->isNew());
     $default_type = $scheduled_update_type->getUpdateEntityType();
     $form['update_entity_type'] = ['#type' => 'select', '#title' => $this->t('Entity Type'), '#description' => $this->t('The entity type to update. This <strong>cannot</strong> be changed after this type is created.'), '#options' => $this->entityTypeOptions(), '#default_value' => $default_type, '#required' => TRUE, '#disabled' => !$scheduled_update_type->isNew()];
     // @todo Remove when bug is fixed.
     if (!$form['update_entity_type']['#disabled']) {
         // Just to duplicate issues on d.o for now.
         $form['update_entity_type']['#description'] .= '<br /><strong>**KNOWN BUG**</strong> : Ajax error when selecting one entity type and then selecting another: https://www.drupal.org/node/2643934';
     }
     // On Add give the user the option to create referencing entity reference field.
     $ajax = ['#limit_validation_errors' => array(), '#ajax' => array('wrapper' => 'type-dependent-set', 'callback' => '::updateTypeDependentSet', 'method' => 'replace')];
     $form['update_entity_type'] += $ajax;
     $form['type_dependent_elements'] = [];
     // @todo Should the runner configuration form even be displayed before entity type is selected?
     $form['type_dependent_elements']['update_runner'] = $this->createRunnerElements($form_state);
     $form['type_dependent_elements']['update_runner']['id'] += $ajax;
     if ($this->entity->isNew()) {
         $form['type_dependent_elements']['reference_settings'] = $this->createNewFieldsElements($form, $form_state);
     }
     $form['type_dependent_elements'] += ['#type' => 'container', '#prefix' => '<div id="type-dependent-set" >', '#suffix' => '</div>'];
     $form['field_map'] = $this->createFieldMapElements();
     /* You will need additional form elements for your custom properties. */
     return $form;
 }
开发者ID:tedbow,项目名称:scheduled-updates-demo,代码行数:32,代码来源:ScheduledUpdateTypeForm.php

示例13: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var \Drupal\media_entity\MediaBundleInterface $bundle */
     $form['#entity'] = $bundle = $this->entity;
     $form_state->set('bundle', $bundle->id());
     if ($this->operation == 'add') {
         $form['#title'] = $this->t('Add media bundle');
     } elseif ($this->operation == 'edit') {
         $form['#title'] = $this->t('Edit %label media bundle', array('%label' => $bundle->label()));
     }
     $form['label'] = array('#title' => t('Label'), '#type' => 'textfield', '#default_value' => $bundle->label(), '#description' => t('The human-readable name of this media bundle.'), '#required' => TRUE, '#size' => 30);
     // @todo: '#disabled' not always FALSE.
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $bundle->id(), '#maxlength' => 32, '#disabled' => FALSE, '#machine_name' => array('exists' => array('\\Drupal\\media_entity\\Entity\\MediaBundle', 'exists'), 'source' => array('label')), '#description' => t('A unique machine-readable name for this media bundle.'));
     $form['description'] = array('#title' => t('Description'), '#type' => 'textarea', '#default_value' => $bundle->getDescription(), '#description' => t('Describe this media bundle. The text will be displayed on the <em>Add new media</em> page.'));
     $plugins = $this->mediaTypeManager->getDefinitions();
     $options = array();
     foreach ($plugins as $plugin => $definition) {
         $options[$plugin] = $definition['label'];
     }
     $form['type'] = array('#type' => 'select', '#title' => t('Type provider'), '#default_value' => $bundle->getType()->getPluginId(), '#options' => $options, '#description' => t('Media type provider plugin that is responsible for additional logic related to this media.'));
     $form['type_configuration'] = array('#type' => 'fieldset', '#title' => t('Type provider configuration'), '#tree' => TRUE);
     foreach ($plugins as $plugin => $definition) {
         $plugin_configuration = $bundle->getType()->getPluginId() == $plugin ? $bundle->type_configuration : array();
         $form['type_configuration'][$plugin] = array('#type' => 'container', '#states' => array('visible' => array(':input[name="type"]' => array('value' => $plugin))));
         /** @var \Drupal\media_entity\MediaTypeBase $instance */
         $instance = $this->mediaTypeManager->createInstance($plugin, $plugin_configuration);
         $form['type_configuration'][$plugin] += $instance->buildConfigurationForm([], $form_state);
         // Store the instance for validate and submit handlers.
         $this->configurableInstances[$plugin] = $instance;
     }
     return $form;
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:36,代码来源:MediaBundleForm.php

示例14: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $backup_migrate_schedule = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Schedule Name'), '#maxlength' => 255, '#default_value' => $backup_migrate_schedule->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $backup_migrate_schedule->id(), '#machine_name' => array('exists' => '\\Drupal\\backup_migrate\\Entity\\Schedule::load'), '#disabled' => !$backup_migrate_schedule->isNew());
     $form['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Schedule enabled'), '#default_value' => $backup_migrate_schedule->get('enabled'));
     $bam = backup_migrate_get_service_object([], ['nobrowser' => TRUE]);
     $form['source_id'] = DrupalConfigHelper::getSourceSelector($bam, t('Backup Source'));
     $form['destination_id'] = DrupalConfigHelper::getDestinationSelector($bam, t('Backup Destination'));
     $form['settings_profile_id'] = DrupalConfigHelper::getSettingsProfileSelector(t('Settings Profile'));
     $period = Schedule::secondsToPeriod($backup_migrate_schedule->get('period'));
     $form['period_container'] = array('#parents' => array(), '#type' => 'fieldset', '#title' => $this->t('Frequency'), '#field_prefix' => $this->t('Run every'), '#attributes' => array('class' => array('container-inline', 'fieldgroup', 'form-composite')));
     $form['period_container']['period_number'] = array('#type' => 'number', '#default_value' => $period['number'], '#min' => 1, '#title' => $this->t('Period number'), '#title_display' => 'invisible', '#size' => 2);
     $form['period_container']['period_type'] = ['#type' => 'select', '#title' => $this->t('Period type'), '#title_display' => 'invisible', '#options' => [], '#default_value' => $period['type']];
     foreach (Schedule::getPeriodTypes() as $key => $type) {
         $form['period_container']['period_type']['#options'][$key] = $type['title'];
     }
     //    $form['keep'] = array(
     //      '#type' => 'textfield',
     //      '#title' => $this->t('Number to keep'),
     //      '#default_value' => $backup_migrate_schedule->get('keep'),
     //      '#description' => $this->t('The number of backups to retain. Once this number is reached, the oldest backup will be deleted to make room for the most recent backup. Leave blank to keep all backups.'),
     //      '#size' => 10,
     //    );
     return $form;
 }
开发者ID:r-daneelolivaw,项目名称:chalk,代码行数:30,代码来源:ScheduleForm.php

示例15: 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;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:29,代码来源:ConfigTestForm.php


注:本文中的Drupal\Core\Entity\EntityForm::form方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。