loadInclude example


  public function buildForm(array $form, FormStateInterface $form_state) {
    // Make sure the install API is available.     include_once DRUPAL_ROOT . '/core/includes/install.inc';

    // Get a list of all available modules that can be uninstalled.     $uninstallable = array_filter($this->moduleExtensionList->getList()function D$module) {
       return empty($module->info['required']) && $module->status;
    });

    // Include system.admin.inc so we can use the sort callbacks.     $this->moduleHandler->loadInclude('system', 'inc', 'system.admin');

    $form['filters'] = [
      '#type' => 'container',
      '#attributes' => [
        'class' => ['table-filter', 'js-show'],
      ],
    ];

    $form['filters']['text'] = [
      '#type' => 'search',
      '#title' => $this->t('Filter modules'),
      
/** * @covers ::loadInclude * * Note we load code, so isolate the test. * * @runInSeparateProcess * @preserveGlobalState disabled */
  public function testLoadInclude() {
    $module_handler = $this->getModuleHandler();
    // Include exists.     $this->assertEquals(__DIR__ . '/modules/module_handler_test/hook_include.inc', $module_handler->loadInclude('module_handler_test', 'inc', 'hook_include'));
    $this->assertTrue(function_exists('module_handler_test_hook_include'));
    // Include doesn't exist.     $this->assertFalse($module_handler->loadInclude('module_handler_test', 'install'));
  }

  /** * Tests invoke methods when module is enabled. * * @covers ::invoke */
  public function testInvokeModuleEnabled() {
    
foreach (entity_test_entity_types() as $entity_type_id) {
      // The entity_test schema is installed by the parent.       if ($entity_type_id != 'entity_test') {
        $this->installEntitySchema($entity_type_id);
      }
    }

    $this->installConfig(['language']);

    // Create the test field.     $this->container->get('module_handler')->loadInclude('entity_test', 'install');
    entity_test_install();

    // Enable translations for the test entity type.     $this->state->set('entity_test.translation', TRUE);

    // Create a translatable test field.     $this->fieldName = mb_strtolower($this->randomMachineName() . '_field_name');

    // Create an untranslatable test field.     $this->untranslatableFieldName = mb_strtolower($this->randomMachineName() . '_field_name');

    
/** * {@inheritdoc} */
  public function hasInvalidToken() {
    return $this->invalidToken;
  }

  /** * Wraps ModuleHandler::loadInclude(). */
  protected function moduleLoadInclude($module$type$name = NULL) {
    return \Drupal::moduleHandler()->loadInclude($module$type$name);
  }

}

  protected static $modules = [
    'locale',
    'locale_test',
    'system',
  ];

  /** * Checks if a list of translatable projects gets build. */
  public function testUpdateProjects() {
    $this->container->get('module_handler')->loadInclude('locale', 'compare.inc');

    // Make the test modules look like a normal custom module. I.e. make the     // modules not hidden. locale_test_system_info_alter() modifies the project     // info of the locale_test and locale_test_translate modules.     \Drupal::state()->set('locale.test_system_info_alter', TRUE);

    // Check if interface translation data is collected from hook_info.     $projects = locale_translation_project_list();
    $this->assertArrayNotHasKey('locale_test_translate', $projects);
    $this->assertEquals('core/modules/locale/test/test.%language.po', $projects['locale_test']['info']['interface translation server pattern']);
    $this->assertEquals('locale_test', $projects['locale_test']['name']);
  }
public function testLoadInclude() {
    $type = 'some_type';
    $module = 'some_module';
    $name = 'some_name';
    $form_state = $this->getMockBuilder('Drupal\Core\Form\FormState')
      ->onlyMethods(['moduleLoadInclude'])
      ->getMock();
    $form_state->expects($this->once())
      ->method('moduleLoadInclude')
      ->with($module$type$name)
      ->willReturn(TRUE);
    $this->assertTrue($form_state->loadInclude($module$type$name));
  }

  /** * @covers ::loadInclude */
  public function testLoadIncludeNoName() {
    $type = 'some_type';
    $module = 'some_module';
    $form_state = $this->getMockBuilder('Drupal\Core\Form\FormState')
      ->onlyMethods(['moduleLoadInclude'])
      ->getMock();
    

  protected static $modules = [
    'locale',
    'locale_test',
    'system',
  ];

  /** * Checks if a list of translatable projects gets built. */
  public function testBuildProjects() {
    $this->container->get('module_handler')->loadInclude('locale', 'compare.inc');
    /** @var \Drupal\Core\Extension\ExtensionList $module_list */
    $module_list = \Drupal::service('extension.list.module');

    // Make the test modules look like a normal custom module. I.e. make the     // modules not hidden. locale_test_system_info_alter() modifies the project     // info of the locale_test and locale_test_translate modules.     \Drupal::state()->set('locale.test_system_info_alter', TRUE);

    // Confirm the project name and core value before the module is altered.     $projects = locale_translation_build_projects();
    $this->assertSame('locale_test', $projects['locale_test']->name);
    
public static function create(ContainerInterface $container) {
    return new static(
      $container->get('module_handler'),
      $container->get('state')
    );
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $this->moduleHandler->loadInclude('update', 'inc', 'update.manager');

    $form['last_check'] = [
      '#theme' => 'update_last_check',
      '#last' => $this->state->get('update.last_check', 0),
    ];

    if (!_update_manager_check_backends($form, 'update')) {
      return $form;
    }

    $available = update_get_available(TRUE);
    

  public static function getTablesSpecification(ModuleHandlerInterface $handler, string $module): array {
    if ($handler->loadInclude($module, 'install')) {
      return $handler->invoke($module, 'schema') ?? [];
    }
    return [];
  }

}

  public function processItem($data) {
    $this->moduleHandler->loadInclude('locale', 'batch.inc');
    [$function$args] = $data;

    // We execute batch operation functions here to check, download and import     // the translation files. Batch functions use a context variable as last     // argument which is passed by reference. When a batch operation is called     // for the first time a default batch context is created. When called     // iterative (usually the batch import function) the batch context is passed     // through via the queue and is part of the $data.     $last = count($args) - 1;
    if (!is_array($args[$last]) || !isset($args[$last]['finished'])) {
      $batch_context = [
        

  public function testLoadInclude($expected$module$type$name) {
    $this->decoratedFormState->loadInclude($module$type$name)
      ->willReturn($expected)
      ->shouldBeCalled();

    $this->assertSame($expected$this->formStateDecoratorBase->loadInclude($module$type$name));
  }

  /** * Provides data to self::testLoadInclude(). */
  public function providerLoadInclude() {
    return [
      
protected function setUp(): void {
    parent::setUp();

    foreach (entity_test_entity_types() as $entity_type_id) {
      // The entity_test schema is installed by the parent.       if ($entity_type_id != 'entity_test') {
        $this->installEntitySchema($entity_type_id);
      }
    }

    // Create the test field.     $this->container->get('module_handler')->loadInclude('entity_test', 'install');
    entity_test_install();

    // Install required default configuration for filter module.     $this->installConfig(['system', 'filter']);
  }

  /** * Creates a test entity. * * @return \Drupal\Core\Entity\EntityInterface */
  
/** * {@inheritdoc} */
  public function getForm(ViewEntityInterface $view$display_id$js) {
    /** @var \Drupal\Core\Form\FormStateInterface $form_state */
    $form_state = $this->getFormState($view$display_id$js);
    $view = $form_state->get('view');
    $form_key = $form_state->get('form_key');

    // @todo Remove the need for this.     \Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');

    // Reset the cache of IDs. Drupal rather aggressively prevents ID     // duplication but this causes it to remember IDs that are no longer even     // being used.     Html::resetSeenIds();

    // check to see if this is the top form of the stack. If it is, pop     // it off; if it isn't, the user clicked somewhere else and the stack is     // now irrelevant.     if (!empty($view->stack)) {
      $identifier = implode('-', array_filter([$form_key$view->id()$display_id$form_state->get('type')$form_state->get('id')]));
      
$container->get('update.root'),
      $container->get('module_handler'),
      $container->getParameter('site.path'),
      $container->get('plugin.manager.archiver')
    );
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $this->moduleHandler->loadInclude('update', 'inc', 'update.manager');
    if (!_update_manager_check_backends($form, 'install')) {
      return $form;
    }

    $form['help_text'] = [
      '#prefix' => '<p>',
      '#markup' => $this->t('You can find <a href=":module_url">modules</a> and <a href=":theme_url">themes</a> on <a href=":drupal_org_url">drupal.org</a>. The following file extensions are supported: %extensions.', [
        ':module_url' => 'https://www.drupal.org/project/modules',
        ':theme_url' => 'https://www.drupal.org/project/themes',
        ':drupal_org_url' => 'https://www.drupal.org',
        '%extensions' => $this->archiverManager->getExtensions(),
      ]),
$this->installEntitySchema('entity_test');
    $this->installEntitySchema('entity_test_mul');
    $this->installEntitySchema('entity_test_mul_langcode_key');
    $this->installEntitySchema('entity_test_mul_changed');
    $this->installEntitySchema('entity_test_rev');
    $this->installEntitySchema('entity_test_mulrev');
    $this->installEntitySchema('entity_test_mulrev_changed');

    // The users table is needed for creating dummy user accounts.     $this->installEntitySchema('user');
    // Register entity_test text field.     $this->container->get('module_handler')->loadInclude('entity_test', 'install');
    entity_test_install();
  }

  /** * Tests hook_entity_field_access() and hook_entity_field_access_alter(). * * @see entity_test_entity_field_access() * @see entity_test_entity_field_access_alter() */
  public function testFieldAccess() {
    $values = [
      
Home | Imprint | This part of the site doesn't use cookies.