Verified Commit 451be835 authored by Dave Long's avatar Dave Long
Browse files

Issue #3417675 by quietone, arunkumark: Correct mymodule, mydriver and anothermodule

parent 2624df1b
Loading
Loading
Loading
Loading
Loading
+24 −24
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@
 *
 * Configuration is divided into individual objects, each of which has a
 * unique name or key. Some modules will have only one configuration object,
 * typically called 'mymodule.settings'; some modules will have many. Within
 * typically called 'my_module.settings'; some modules will have many. Within
 * a configuration object, configuration settings have data types (integer,
 * string, Boolean, etc.) and settings can also exist in a nested hierarchy,
 * known as a "mapping".
@@ -283,10 +283,10 @@
 * The first task in using the simple configuration API is to define the
 * configuration file structure, file name, and schema of your settings (see
 * @ref sec_yaml above). Once you have done that, you can retrieve the active
 * configuration object that corresponds to configuration file mymodule.foo.yml
 * configuration object that corresponds to configuration file my_module.foo.yml
 * with a call to:
 * @code
 * $config = \Drupal::config('mymodule.foo');
 * $config = \Drupal::config('my_module.foo');
 * @endcode
 *
 * This will be an object of class \Drupal\Core\Config\Config, which has methods
@@ -313,7 +313,7 @@
 * you will instead need to get the Config object by making a call to
 * getEditable() on the config factory:
 * @code
 * $config =\Drupal::service('config.factory')->getEditable('mymodule.foo');
 * $config =\Drupal::service('config.factory')->getEditable('my_module.foo');
 * @endcode
 *
 * Individual configuration values can be changed or added using the set()
@@ -430,7 +430,7 @@
 *
 * Example:
 * @code
 * $cid = 'mymodule_example:' . \Drupal::languageManager()->getCurrentLanguage()->getId();
 * $cid = 'my_module_example:' . \Drupal::languageManager()->getCurrentLanguage()->getId();
 *
 * $data = NULL;
 * if ($cache = \Drupal::cache()->get($cid)) {
@@ -1415,8 +1415,8 @@
 *   class and the parent (default) plugin manager service to inherit
 *   constructor arguments:
 *   @code
 *   plugin.manager.mymodule:
 *     class: Drupal\mymodule\MyPluginManager
 *   plugin.manager.my_module:
 *     class: Drupal\my_module\MyPluginManager
 *     parent: default_plugin_manager
 *   @endcode
 * - If your plugin is configurable, you will also need to define the
@@ -1701,7 +1701,7 @@
 *
 * Here is an example of a Form class:
 * @code
 * namespace Drupal\mymodule\Form;
 * namespace Drupal\my_module\Form;
 *
 * use Drupal\Core\Form\FormBase;
 * use Drupal\Core\Form\FormStateInterface;
@@ -1739,7 +1739,7 @@
 * \Drupal::formBuilder()->getForm() should be used to handle retrieving,
 * processing, and displaying a rendered HTML form. Given the ExampleForm
 * defined above,
 * \Drupal::formBuilder()->getForm('Drupal\mymodule\Form\ExampleForm') would
 * \Drupal::formBuilder()->getForm('Drupal\my_module\Form\ExampleForm') would
 * return the rendered HTML of the form defined by ExampleForm::buildForm(), or
 * call the validateForm() and submitForm(), methods depending on the current
 * processing state.
@@ -1752,7 +1752,7 @@
 * For example:
 * @code
 * $extra = '612-123-4567';
 * $form = \Drupal::formBuilder()->getForm('Drupal\mymodule\Form\ExampleForm', $extra);
 * $form = \Drupal::formBuilder()->getForm('Drupal\my_module\Form\ExampleForm', $extra);
 * ...
 * public function buildForm(array $form, FormStateInterface $form_state, $extra = NULL)
 *   $form['phone_number'] = array(
@@ -1774,7 +1774,7 @@
 *   path: '/example-form'
 *   defaults:
 *     _title: 'Example form'
 *     _form: '\Drupal\mymodule\Form\ExampleForm'
 *     _form: '\Drupal\my_module\Form\ExampleForm'
 * @endcode
 *
 * The $form argument to form-related functions is a specialized render array
@@ -1925,17 +1925,17 @@
function hook_cron() {
  // Short-running operation example, not using a queue:
  // Delete all expired records since the last cron run.
  $expires = \Drupal::state()->get('mymodule.last_check', 0);
  $expires = \Drupal::state()->get('my_module.last_check', 0);
  $request_time = \Drupal::time()->getRequestTime();
  \Drupal::database()->delete('mymodule_table')
  \Drupal::database()->delete('my_module_table')
    ->condition('expires', $expires, '>=')
    ->execute();
  \Drupal::state()->set('mymodule.last_check', $request_time);
  \Drupal::state()->set('my_module.last_check', $request_time);

  // Long-running operation example, leveraging a queue:
  // Queue news feeds for updates once their refresh interval has elapsed.
  $queue = \Drupal::queue('mymodule.feeds');
  $ids = \Drupal::entityTypeManager()->getStorage('mymodule_feed')->getFeedIdsToRefresh();
  $queue = \Drupal::queue('my_module.feeds');
  $ids = \Drupal::entityTypeManager()->getStorage('my_module_feed')->getFeedIdsToRefresh();
  foreach (Feed::loadMultiple($ids) as $feed) {
    if ($queue->createItem($feed)) {
      // Add timestamp to avoid queueing item more than once.
@@ -1943,7 +1943,7 @@ function hook_cron() {
      $feed->save();
    }
  }
  $ids = \Drupal::entityQuery('mymodule_feed')
  $ids = \Drupal::entityQuery('my_module_feed')
    ->accessCheck(FALSE)
    ->condition('queued', $request_time - (3600 * 6), '<')
    ->execute();
@@ -1965,7 +1965,7 @@ function hook_cron() {
 * @see hook_data_type_info()
 */
function hook_data_type_info_alter(&$data_types) {
  $data_types['email']['class'] = '\Drupal\mymodule\Type\Email';
  $data_types['email']['class'] = '\Drupal\my_module\Type\Email';
}

/**
@@ -1986,7 +1986,7 @@ function hook_data_type_info_alter(&$data_types) {
function hook_queue_info_alter(&$queues) {
  // This site has many feeds so let's spend 90 seconds on each cron run
  // updating feeds instead of the default 60.
  $queues['mymodule_feeds']['cron']['time'] = 90;
  $queues['my_module_feeds']['cron']['time'] = 90;
}

/**
@@ -1999,7 +1999,7 @@ function hook_condition_info_alter(array &$definitions) {
  // Add custom or modify existing condition definitions.
  if (isset($definitions['node_type']) && $definitions['node_type']['class'] == 'Drupal\node\Plugin\Condition\NodeType') {
    // If the node_type's class is unaltered, use a custom implementation.
    $definitions['node_type']['class'] = 'Drupal\mymodule\Plugin\Condition\NodeType';
    $definitions['node_type']['class'] = 'Drupal\my_module\Plugin\Condition\NodeType';
  }
}

@@ -2302,7 +2302,7 @@ function hook_config_schema_info_alter(&$definitions) {
 * @see \Drupal\Core\Validation\Annotation\Constraint
 */
function hook_validation_constraint_alter(array &$definitions) {
  $definitions['Null']['class'] = '\Drupal\mymodule\Plugin\Validation\Constraints\MyClass';
  $definitions['Null']['class'] = '\Drupal\my_module\Plugin\Validation\Constraints\MyClass';
}

/**
@@ -2645,8 +2645,8 @@ function hook_validation_constraint_alter(array &$definitions) {
 * @code
 * public function counter(Request $request) {
 *   $session = $request->getSession();
 *   $count = $session->get('mymodule.counter', 0) + 1;
 *   $session->set('mymodule.counter', $count);
 *   $count = $session->get('my_module.counter', 0) + 1;
 *   $session->set('my_module.counter', $count);
 *
 *   return [
 *     '#markup' => $this->t('Page Views: @count', ['@count' => $count]),
@@ -2658,7 +2658,7 @@ function hook_validation_constraint_alter(array &$definitions) {
 *
 * public function reset(Request $request) {
 *   $session = $request->getSession();
 *   $session->remove('mymodule.counter');
 *   $session->remove('my_module.counter');
 * }
 * @endcode
 *
+1 −1
Original line number Diff line number Diff line
@@ -371,7 +371,7 @@ function drupal_maintenance_theme() {
 *
 * Example:
 * @code
 * function mymodule_log_stream_handle($new_handle = NULL) {
 * function my_module_log_stream_handle($new_handle = NULL) {
 *   static $handle;
 *   if (isset($new_handle)) {
 *     $handle = $new_handle;
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ protected function configure() {
      ->setDescription('Dumps a generated proxy class into its appropriate namespace.')
      ->addUsage('\'Drupal\Core\Batch\BatchStorage\' "core/lib/Drupal/Core"')
      ->addUsage('\'Drupal\block\BlockRepository\' "core/modules/block/src"')
      ->addUsage('\'Drupal\mymodule\MyClass\' "modules/contrib/mymodule/src"');
      ->addUsage('\'Drupal\my_module\MyClass\' "modules/contrib/my_module/src"');
  }

  /**
+2 −4
Original line number Diff line number Diff line
@@ -2,20 +2,18 @@

namespace Drupal\Core\Database;

// cSpell:ignore mydriver

/**
 * Represents a prepared statement.
 *
 * Child implementations should either extend StatementWrapperIterator:
 * @code
 * class Drupal\mymodule\Driver\Database\mydriver\Statement extends Drupal\Core\Database\StatementWrapperIterator {}
 * class Drupal\my_module\Driver\Database\my_driver\Statement extends Drupal\Core\Database\StatementWrapperIterator {}
 * @endcode
 * or define their own class. If defining their own class, they will also have
 * to implement either the \Iterator or \IteratorAggregate interface before
 * Drupal\Core\Database\StatementInterface:
 * @code
 * class Drupal\mymodule\Driver\Database\mydriver\Statement implements Iterator, Drupal\Core\Database\StatementInterface {}
 * class Drupal\my_module\Driver\Database\my_driver\Statement implements Iterator, Drupal\Core\Database\StatementInterface {}
 * @endcode
 *
 * @ingroup database
+35 −35
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@
 * - The entity-type-specific hooks are represented in the list below as
 *   hook_ENTITY_TYPE_... (hook_ENTITY_TYPE_create() in this example). To
 *   implement one of these hooks for an entity whose machine name is "foo",
 *   define a function called mymodule_foo_create(), for instance. Also note
 *   define a function called my_module_foo_create(), for instance. Also note
 *   that the entity or array of entities that are passed into a specific-type
 *   hook are of the specific entity class, not the generic Entity class, so in
 *   your implementation, you can make the $entity argument something like $node
@@ -817,7 +817,7 @@ function hook_entity_type_build(array &$entity_types) {
  /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
  // Add a form for a custom node form without overriding the default
  // node form. To override the default node form, use hook_entity_type_alter().
  $entity_types['node']->setFormClass('mymodule_foo', 'Drupal\mymodule\NodeFooForm');
  $entity_types['node']->setFormClass('my_module_foo', 'Drupal\my_module\NodeFooForm');
}

/**
@@ -846,7 +846,7 @@ function hook_entity_type_alter(array &$entity_types) {
  /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
  // Set the controller class for nodes to an alternate implementation of the
  // Drupal\Core\Entity\EntityStorageInterface interface.
  $entity_types['node']->setStorageClass('Drupal\mymodule\MyCustomNodeStorage');
  $entity_types['node']->setStorageClass('Drupal\my_module\MyCustomNodeStorage');
}

/**
@@ -901,7 +901,7 @@ function hook_entity_bundle_info() {
function hook_entity_bundle_info_alter(&$bundles) {
  $bundles['user']['user']['label'] = t('Full account');
  // Override the bundle class for the "article" node type in a custom module.
  $bundles['node']['article']['class'] = 'Drupal\mymodule\Entity\Article';
  $bundles['node']['article']['class'] = 'Drupal\my_module\Entity\Article';
}

/**
@@ -1042,7 +1042,7 @@ function hook_entity_preload(array $ids, $entity_type_id) {
  $entities = [];

  foreach ($ids as $id) {
    $entities[] = mymodule_swap_revision($id);
    $entities[] = my_module_swap_revision($id);
  }

  return $entities;
@@ -1067,7 +1067,7 @@ function hook_entity_preload(array $ids, $entity_type_id) {
 */
function hook_entity_load(array $entities, $entity_type_id) {
  foreach ($entities as $entity) {
    $entity->foo = mymodule_add_something($entity);
    $entity->foo = my_module_add_something($entity);
  }
}

@@ -1082,7 +1082,7 @@ function hook_entity_load(array $entities, $entity_type_id) {
 */
function hook_ENTITY_TYPE_load($entities) {
  foreach ($entities as $entity) {
    $entity->foo = mymodule_add_something($entity);
    $entity->foo = my_module_add_something($entity);
  }
}

@@ -1100,7 +1100,7 @@ function hook_ENTITY_TYPE_load($entities) {
 */
function hook_entity_storage_load(array $entities, $entity_type) {
  foreach ($entities as $entity) {
    $entity->foo = mymodule_add_something_uncached($entity);
    $entity->foo = my_module_add_something_uncached($entity);
  }
}

@@ -1116,7 +1116,7 @@ function hook_entity_storage_load(array $entities, $entity_type) {
 */
function hook_ENTITY_TYPE_storage_load(array $entities) {
  foreach ($entities as $entity) {
    $entity->foo = mymodule_add_something_uncached($entity);
    $entity->foo = my_module_add_something_uncached($entity);
  }
}

@@ -1517,12 +1517,12 @@ function hook_ENTITY_TYPE_revision_delete(\Drupal\Core\Entity\EntityInterface $e
 */
function hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
  // Only do the extra work if the component is configured to be displayed.
  // This assumes a 'mymodule_addition' extra field has been defined for the
  // This assumes a 'my_module_addition' extra field has been defined for the
  // entity bundle in hook_entity_extra_field_info().
  if ($display->getComponent('mymodule_addition')) {
    $build['mymodule_addition'] = [
      '#markup' => mymodule_addition($entity),
      '#theme' => 'mymodule_my_additional_field',
  if ($display->getComponent('my_module_addition')) {
    $build['my_module_addition'] = [
      '#markup' => my_module_addition($entity),
      '#theme' => 'my_module_my_additional_field',
    ];
  }
}
@@ -1550,12 +1550,12 @@ function hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $en
 */
function hook_ENTITY_TYPE_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
  // Only do the extra work if the component is configured to be displayed.
  // This assumes a 'mymodule_addition' extra field has been defined for the
  // This assumes a 'my_module_addition' extra field has been defined for the
  // entity bundle in hook_entity_extra_field_info().
  if ($display->getComponent('mymodule_addition')) {
    $build['mymodule_addition'] = [
      '#markup' => mymodule_addition($entity),
      '#theme' => 'mymodule_my_additional_field',
  if ($display->getComponent('my_module_addition')) {
    $build['my_module_addition'] = [
      '#markup' => my_module_addition($entity),
      '#theme' => 'my_module_my_additional_field',
    ];
  }
}
@@ -1660,16 +1660,16 @@ function hook_entity_prepare_view($entity_type_id, array $entities, array $displ
  // Load a specific node into the user object for later theming.
  if (!empty($entities) && $entity_type_id == 'user') {
    // Only do the extra work if the component is configured to be
    // displayed. This assumes a 'mymodule_addition' extra field has been
    // displayed. This assumes a 'my_module_addition' extra field has been
    // defined for the entity bundle in hook_entity_extra_field_info().
    $ids = [];
    foreach ($entities as $id => $entity) {
      if ($displays[$entity->bundle()]->getComponent('mymodule_addition')) {
      if ($displays[$entity->bundle()]->getComponent('my_module_addition')) {
        $ids[] = $id;
      }
    }
    if ($ids) {
      $nodes = mymodule_get_user_nodes($ids);
      $nodes = my_module_get_user_nodes($ids);
      foreach ($ids as $id) {
        $entities[$id]->user_node = $nodes[$id];
      }
@@ -1925,11 +1925,11 @@ function hook_entity_form_display_alter(\Drupal\Core\Entity\Display\EntityFormDi
function hook_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  if ($entity_type->id() == 'node') {
    $fields = [];
    $fields['mymodule_text'] = BaseFieldDefinition::create('string')
    $fields['my_module_text'] = BaseFieldDefinition::create('string')
      ->setLabel(t('The text'))
      ->setDescription(t('A text property added by mymodule.'))
      ->setDescription(t('A text property added by my_module.'))
      ->setComputed(TRUE)
      ->setClass('\Drupal\mymodule\EntityComputedText');
      ->setClass('\Drupal\my_module\EntityComputedText');

    return $fields;
  }
@@ -1951,9 +1951,9 @@ function hook_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $en
 * https://www.drupal.org/node/2346329.
 */
function hook_entity_base_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  // Alter the mymodule_text field to use a custom class.
  if ($entity_type->id() == 'node' && !empty($fields['mymodule_text'])) {
    $fields['mymodule_text']->setClass('\Drupal\anothermodule\EntityComputedText');
  // Alter the my_module_text field to use a custom class.
  if ($entity_type->id() == 'node' && !empty($fields['my_module_text'])) {
    $fields['my_module_text']->setClass('\Drupal\another_module\EntityComputedText');
  }
}

@@ -1990,8 +1990,8 @@ function hook_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $
  // Add a property only to nodes of the 'article' bundle.
  if ($entity_type->id() == 'node' && $bundle == 'article') {
    $fields = [];
    $storage_definitions = mymodule_entity_field_storage_info($entity_type);
    $fields['mymodule_bundle_field'] = FieldDefinition::createFromFieldStorageDefinition($storage_definitions['mymodule_bundle_field'])
    $storage_definitions = my_module_entity_field_storage_info($entity_type);
    $fields['my_module_bundle_field'] = FieldDefinition::createFromFieldStorageDefinition($storage_definitions['my_module_bundle_field'])
      ->setLabel(t('Bundle Field'));
    return $fields;
  }
@@ -2016,9 +2016,9 @@ function hook_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $
 * https://www.drupal.org/node/2346347.
 */
function hook_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle) {
  if ($entity_type->id() == 'node' && $bundle == 'article' && !empty($fields['mymodule_text'])) {
    // Alter the mymodule_text field to use a custom class.
    $fields['mymodule_text']->setClass('\Drupal\anothermodule\EntityComputedText');
  if ($entity_type->id() == 'node' && $bundle == 'article' && !empty($fields['my_module_text'])) {
    // Alter the my_module_text field to use a custom class.
    $fields['my_module_text']->setClass('\Drupal\another_module\EntityComputedText');
  }
}

@@ -2072,8 +2072,8 @@ function hook_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface
 */
function hook_entity_field_storage_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  // Alter the max_length setting.
  if ($entity_type->id() == 'node' && !empty($fields['mymodule_text'])) {
    $fields['mymodule_text']->setSetting('max_length', 128);
  if ($entity_type->id() == 'node' && !empty($fields['my_module_text'])) {
    $fields['my_module_text']->setSetting('max_length', 128);
  }
}

Loading