Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何连接代码以更改Drupal模块行为?_Drupal_Drupal 8 - Fatal编程技术网

如何连接代码以更改Drupal模块行为?

如何连接代码以更改Drupal模块行为?,drupal,drupal-8,Drupal,Drupal 8,Drupal不允许我删除扩展(商业),因为有些字段需要手动删除。下文详细介绍了这一问题 解决方案是向文件中添加一些代码,如下面问题的#11所述 基本上,我需要以编程方式删除一个字段,而我以前从未这样做过。写作有点像钩子(?) 我尝试在原始代码之前、之后粘贴建议的代码,并用建议的代码替换原始代码 每次更改代码后,我都会重新启动服务器,运行cron并清除缓存 但我仍然无法从drupal卸载exension,因为我有以下消息: The following reason prevents Commerc

Drupal不允许我删除扩展(商业),因为有些字段需要手动删除。下文详细介绍了这一问题

解决方案是向文件中添加一些代码,如下面问题的#11所述

基本上,我需要以编程方式删除一个字段,而我以前从未这样做过。写作有点像钩子(?)

我尝试在原始代码之前、之后粘贴建议的代码,并用建议的代码替换原始代码

每次更改代码后,我都会重新启动服务器,运行cron并清除缓存

但我仍然无法从drupal卸载exension,因为我有以下消息:

The following reason prevents Commerce Recurring from being uninstalled:

    The Billing period field type is used in the following fields: commerce_order.billing_period, commerce_order_item.billing_period
以下问题的详情:

请跳到第11页

建议适用的代码:


function commerce_recurring_update_8101(&$sandbox) {

\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.billing_schedule')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.order_items')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_standalone.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_standalone.subscription')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_product_variation.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_product_variation.subscription')->delete();
}

function commerce_recurring_update_8102(&$sandbox) {
\Drupal::entityTypeManager()->getStorage('commerce_order_type')->load('recurring')->delete();
\Drupal::entityTypeManager()->getStorage('commerce_order_item_type')->load('recurring_standalone')->delete();
\Drupal::entityTypeManager()->getStorage('commerce_order_item_type')->load('recurring_product_variation')->delete();

}
我的文件中的原始代码:

/**
 * Add the 'trial_starts' and "trial_ends" fields to subscriptions.
 */
function commerce_recurring_update_8101(&$sandbox) {
  $fields = [];
  $fields['trial_starts'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Trial starts'))
    ->setDescription(t('The time when the subscription trial starts.'))
    ->setRequired(FALSE)
    ->setDisplayOptions('view', [
      'label' => 'hidden',
      'type' => 'timestamp',
      'weight' => 0,
    ])
    ->setDisplayOptions('form', [
      'type' => 'datetime_timestamp',
      'weight' => 0,
    ])
    ->setDisplayConfigurable('form', TRUE);

  $fields['trial_ends'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Trial ends'))
    ->setDescription(t('The time when the subscription trial ends.'))
    ->setRequired(FALSE)
    ->setDisplayOptions('view', [
      'label' => 'hidden',
      'type' => 'timestamp',
      'weight' => 0,
    ])
    ->setDisplayOptions('form', [
      'type' => 'datetime_timestamp',
      'weight' => 0,
 ])
    ->setDisplayOptions('form', [
      'type' => 'datetime_timestamp',
      'weight' => 0,
    ])
    ->setDisplayConfigurable('form', TRUE);

  $update_manager = \Drupal::entityDefinitionUpdateManager();
  foreach ($fields as $name => $storage_definition) {
    $update_manager->installFieldStorageDefinition($name, 'commerce_subscription', 'commerce_recurring', $storage_definition);
  }
}

/**
 * Make the billing_schedule field required on subscriptions.
 */
function commerce_recurring_update_8102() {
  $entity_definition_update = \Drupal::entityDefinitionUpdateManager();
  $field_definition = $entity_definition_update->getFieldStorageDefinition('billing_schedule', 'commerce_subscription');
  $field_definition->setRequired(TRUE);
  $entity_definition_update->updateFieldStorageDefinition($field_definition);
}