Example #1
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var \Drupal\commerce_product\Entity\ProductTypeInterface $product_type */
     $product_type = $this->entity;
     $variation_types = $this->variationTypeStorage->loadMultiple();
     $variation_types = array_map(function ($variation_type) {
         return $variation_type->label();
     }, $variation_types);
     // Create an empty product to get the default status value.
     // @todo Clean up once https://www.drupal.org/node/2318187 is fixed.
     if ($this->operation == 'add') {
         $product = $this->entityTypeManager->getStorage('commerce_product')->create(['type' => $product_type->uuid()]);
     } else {
         $product = $this->entityTypeManager->getStorage('commerce_product')->create(['type' => $product_type->id()]);
     }
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $product_type->label(), '#required' => TRUE];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $product_type->id(), '#machine_name' => ['exists' => '\\Drupal\\commerce_product\\Entity\\ProductType::load'], '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH];
     $form['description'] = ['#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $product_type->getDescription()];
     $form['variationType'] = ['#type' => 'select', '#title' => $this->t('Product variation type'), '#default_value' => $product_type->getVariationType(), '#options' => $variation_types, '#required' => TRUE];
     $form['product_status'] = ['#type' => 'checkbox', '#title' => t('Publish new products of this type by default.'), '#default_value' => $product->isPublished()];
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = ['#type' => 'details', '#title' => $this->t('Language settings'), '#group' => 'additional_settings'];
         $form['language']['language_configuration'] = ['#type' => 'language_configuration', '#entity_information' => ['entity_type' => 'commerce_product', 'bundle' => $product_type->id()], '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('commerce_product', $product_type->id())];
         $form['#submit'][] = 'language_configuration_element_submit';
     }
     return $this->protectBundleIdElement($form);
 }
  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $paymentInformationType = $this->entity;

    $form['label'] = array(
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
      '#maxlength' => 255,
      '#default_value' => $paymentInformationType->label(),
      '#description' => $this->t('Label for the payment information type.'),
      '#required' => TRUE,
    );

    $form['id'] = array(
      '#type' => 'machine_name',
      '#default_value' => $paymentInformationType->id(),
      '#machine_name' => array(
        'exists' => array($this->paymentInfoTypeStorage, 'load'),
        'source' => array('label'),
      ),
      '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
    );

    $form['description'] = array(
      '#title' => t('Description'),
      '#type' => 'textarea',
      '#default_value' => $paymentInformationType->getDescription(),
      '#description' => $this->t('Description of this payment information type'),
    );

    return $this->protectBundleIdElement($form);;
  }
Example #3
0
 /**
  * {@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');
     $form = parent::form($form, $form_state);
     return $this->protectBundleIdElement($form);
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var \Drupal\commerce_product\Entity\ProductVariationTypeInterface $variation_type */
     $variation_type = $this->entity;
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $variation_type->label(), '#required' => TRUE];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $variation_type->id(), '#machine_name' => ['exists' => '\\Drupal\\commerce_product\\Entity\\ProductVariationType::load'], '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH];
     $form['generateTitle'] = ['#type' => 'checkbox', '#title' => t('Generate variation titles based on attribute values.'), '#default_value' => $variation_type->shouldGenerateTitle()];
     if (\Drupal::moduleHandler()->moduleExists('commerce_order')) {
         // Prepare a list of line item types used to purchase product variations.
         $line_item_type_storage = $this->entityTypeManager->getStorage('commerce_line_item_type');
         $line_item_types = $line_item_type_storage->loadMultiple();
         $line_item_types = array_filter($line_item_types, function ($line_item_type) {
             return $line_item_type->getPurchasableEntityTypeId() == 'commerce_product_variation';
         });
         $line_item_types = array_map(function ($line_item_type) {
             return $line_item_type->label();
         }, $line_item_types);
         $form['lineItemType'] = ['#type' => 'select', '#title' => $this->t('Line item type'), '#default_value' => $variation_type->getLineItemTypeId(), '#options' => $line_item_types, '#empty_value' => '', '#required' => TRUE];
     }
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = ['#type' => 'details', '#title' => $this->t('Language settings'), '#group' => 'additional_settings'];
         $form['language']['language_configuration'] = ['#type' => 'language_configuration', '#entity_information' => ['entity_type' => 'commerce_product_variation', 'bundle' => $variation_type->id()], '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('commerce_product_variation', $variation_type->id())];
         $form['#submit'][] = 'language_configuration_element_submit';
     }
     return $this->protectBundleIdElement($form);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $this->entity->label(), '#required' => TRUE];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $this->entity->id(), '#machine_name' => ['exists' => '\\Drupal\\conference_sessions\\Entity\\RoomType::load'], '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH];
     $form['description'] = ['#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $this->entity->getDescription()];
     return $this->protectBundleIdElement($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(), '#maxlength' => 23);
     $form['actions']['submit']['#value'] = t('Create new set');
     return $this->protectBundleIdElement($form);
 }
Example #7
0
 /**
  * {@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('Add a name for this grade letter set.'), '#required' => TRUE, '#default_value' => $entity->label());
     $form['id'] = array('#type' => 'machine_name', '#machine_name' => array('exists' => '\\Drupal\\gradebook\\Entity\\GradeLetterSet::load', 'source' => array('label'), 'replace_pattern' => '[^a-z0-9-]+', 'replace' => '-'), '#default_value' => $entity->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH);
     $form['actions']['submit']['#value'] = t('Create new set');
     return $this->protectBundleIdElement($form);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 protected function actions(array $form, FormStateInterface $form_state)
 {
     $actions = parent::actions($form, $form_state);
     if (\Drupal::moduleHandler()->moduleExists('field_ui') && $this->getEntity()->isNew()) {
         $actions['save_continue'] = $actions['submit'];
         $actions['save_continue']['#value'] = t('Save and manage fields');
         $actions['save_continue']['#submit'][] = [$this, 'redirectToFieldUI'];
     }
     return $actions;
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $order_type = $this->entity;
     $workflow_manager = \Drupal::service('plugin.manager.workflow');
     $workflows = $workflow_manager->getGroupedLabels('commerce_order');
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $order_type->label(), '#description' => $this->t('Label for the order type.'), '#required' => TRUE];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $order_type->id(), '#machine_name' => ['exists' => '\\Drupal\\commerce_order\\Entity\\OrderType::load', 'source' => ['label']], '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH];
     $form['workflow'] = ['#type' => 'select', '#title' => t('Workflow'), '#options' => $workflows, '#default_value' => $order_type->getWorkflowId(), '#description' => $this->t('Used by all orders of this type.')];
     return $this->protectBundleIdElement($form);
 }
Example #10
0
  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $lineItemType = $this->entity;
    // Prepare the list of purchasable entity types.
    $entityTypes = $this->entityTypeManager->getDefinitions();
    $purchasableEntityTypes = array_filter($entityTypes, function ($entityType) {
      return $entityType->isSubclassOf('\Drupal\commerce\PurchasableEntityInterface');
    });
    $purchasableEntityTypes = array_map(function ($entityType) {
      return $entityType->getLabel();
    }, $purchasableEntityTypes);
    // Prepare the list of order types.
    $orderTypes = $this->entityTypeManager->getStorage('commerce_order_type')
      ->loadMultiple();
    $orderTypes = array_map(function ($orderType) {
      return $orderType->label();
    }, $orderTypes);

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
      '#maxlength' => 255,
      '#default_value' => $lineItemType->label(),
      '#description' => $this->t('Label for the line item type.'),
      '#required' => TRUE,
    ];
    $form['id'] = [
      '#type' => 'machine_name',
      '#default_value' => $lineItemType->id(),
      '#machine_name' => [
        'exists' => '\Drupal\commerce_order\Entity\LineItemType::load',
        'source' => ['label'],
      ],
      '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
    ];
    $form['purchasableEntityType'] = [
      '#type' => 'select',
      '#title' => $this->t('Purchasable entity type'),
      '#default_value' => $lineItemType->getPurchasableEntityType(),
      '#options' => $purchasableEntityTypes,
      '#empty_value' => '',
      '#disabled' => !$lineItemType->isNew(),
    ];
    $form['orderType'] = [
      '#type' => 'select',
      '#title' => $this->t('Order type'),
      '#default_value' => $lineItemType->getOrderType(),
      '#options' => $orderTypes,
      '#required' => TRUE,
    ];

    return $this->protectBundleIdElement($form);
  }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $store_type = $this->entity;
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $store_type->label(), '#description' => $this->t('Label for the store type.'), '#required' => TRUE];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $store_type->id(), '#machine_name' => ['exists' => '\\Drupal\\commerce_store\\Entity\\StoreType::load'], '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH];
     $form['description'] = ['#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $store_type->getDescription()];
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = ['#type' => 'details', '#title' => $this->t('Language settings'), '#group' => 'additional_settings'];
         $form['language']['language_configuration'] = ['#type' => 'language_configuration', '#entity_information' => ['entity_type' => 'commerce_store', 'bundle' => $store_type->id()], '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('commerce_store', $store_type->id())];
         $form['#submit'][] = 'language_configuration_element_submit';
     }
     return $this->protectBundleIdElement($form);
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $rdf_type = $this->entity;
     if ($rdf_type->isNew()) {
         $form['#title'] = $this->t('Add rdf type');
     } else {
         $form['#title'] = $this->t('Edit rdf type');
     }
     $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $rdf_type->label(), '#maxlength' => 255, '#required' => TRUE);
     $form['rid'] = array('#type' => 'machine_name', '#default_value' => $rdf_type->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' => isset($rdf_type->description) ? $rdf_type->description : '');
     $form = parent::form($form, $form_state);
     return $this->protectBundleIdElement($form);
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /* @var \Drupal\block_content\BlockContentTypeInterface $block_type */
     $block_type = $this->entity;
     if ($this->operation == 'add') {
         $form['#title'] = $this->t('Add custom block type');
     } else {
         $form['#title'] = $this->t('Edit %label custom block type', array('%label' => $block_type->label()));
     }
     $form['label'] = array('#type' => 'textfield', '#title' => t('Label'), '#maxlength' => 255, '#default_value' => $block_type->label(), '#description' => t("Provide a label for this block type to help identify it in the administration pages."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $block_type->id(), '#machine_name' => array('exists' => '\\Drupal\\block_content\\Entity\\BlockContentType::load'), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH);
     $form['description'] = array('#type' => 'textarea', '#default_value' => $block_type->getDescription(), '#description' => t('Enter a description for this block type.'), '#title' => t('Description'));
     $form['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $block_type->shouldCreateNewRevision(), '#description' => t('Create a new revision by default for this block type.'));
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = array('#type' => 'details', '#title' => t('Language settings'), '#group' => 'additional_settings');
         $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('block_content', $block_type->id());
         $form['language']['language_configuration'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'block_content', 'bundle' => $block_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 $this->protectBundleIdElement($form);
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($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)));
     }
 }
Example #15
0
  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $productType = $this->entity;
    $variationTypes = $this->variationTypeStorage->loadMultiple();
    $variationTypes = array_map(function($variationType) {
      return $variationType->label();
    }, $variationTypes);

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
      '#maxlength' => 255,
      '#default_value' => $productType->label(),
      '#required' => TRUE,
    ];
    $form['id'] = [
      '#type' => 'machine_name',
      '#default_value' => $productType->id(),
      '#machine_name' => [
        'exists' => '\Drupal\commerce_product\Entity\ProductType::load',
      ],
      '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
    ];
    $form['description'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Description'),
      '#default_value' => $productType->getDescription(),
    ];
    $form['variationType'] = [
      '#type' => 'select',
      '#title' => $this->t('Product variation type'),
      '#default_value' => $productType->getVariationType(),
      '#options' => $variationTypes,
      '#required' => TRUE,
    ];
    $form['digital'] = [
      '#type' => 'checkbox',
      '#title' => t('Digital'),
      '#default_value' => $productType->isDigital(),
      '#description' => t('Products of this type represent digital services.')
    ];

    if ($this->moduleHandler->moduleExists('language')) {
      $form['language'] = [
        '#type' => 'details',
        '#title' => $this->t('Language settings'),
        '#group' => 'additional_settings',
      ];
      $form['language']['language_configuration'] = [
        '#type' => 'language_configuration',
        '#entity_information' => [
          'entity_type' => 'commerce_product',
          'bundle' => $productType->id(),
        ],
        '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('commerce_product', $productType->id()),
      ];
      $form['#submit'][] = 'language_configuration_element_submit';
    }

    return $this->protectBundleIdElement($form);;
  }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function buildEntity(array $form, FormStateInterface $form_state) {
   $entity = parent::buildEntity($form, $form_state);
   $entity->setHandler($entity->get('handler'));
   return $entity;
 }