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


PHP Entity\EntityForm类代码示例

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


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

示例1: 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

示例2: submitForm

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

示例3: 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

示例4: 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

示例5: 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:nsp15,项目名称:Drupal8,代码行数:28,代码来源:VocabularyForm.php

示例6: submitForm

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

示例7: buildEntity

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

示例8: buildForm

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

示例9: validateForm

 /**
  * {@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);
 }
开发者ID:tedbow,项目名称:scheduled-updates-demo,代码行数:10,代码来源:ModerationStateTransitionForm.php

示例10: 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

示例11: form

  /**
   * {@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);
  }
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:36,代码来源:FormBase.php

示例12: actions

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

示例13: 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

示例14: 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

示例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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。