getModuleHandler example

// This form is long and messy enough that the "Administrative title" option     // belongs in "Administrative title" fieldset at the bottom of the form.     $form['more'] = [
      '#type' => 'details',
      '#title' => $this->t('More'),
      '#weight' => 200,
      '#optional' => TRUE,
    ];

    // Allow to alter the default values brought into the form.     // @todo Do we really want to keep this hook.     $this->getModuleHandler()->alter('views_handler_options', $this->options, $this->view);
  }

  /** * Gets the module handler. * * @return \Drupal\Core\Extension\ModuleHandlerInterface */
  protected function getModuleHandler() {
    if (!$this->moduleHandler) {
      $this->moduleHandler = \Drupal::moduleHandler();
    }

    

    ]$this->cacheBackend);
    return $module_handler;
  }

  /** * Tests loading a module. * * @covers ::load */
  public function testLoadModule() {
    $module_handler = $this->getModuleHandler();
    $this->assertFalse(function_exists('module_handler_test_hook'));
    $this->assertTrue($module_handler->load('module_handler_test'));
    $this->assertTrue(function_exists('module_handler_test_hook'));

    $module_handler->addModule('module_handler_test_added', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_added');
    $this->assertFalse(function_exists('module_handler_test_added_hook'), 'Function does not exist before being loaded.');
    $this->assertTrue($module_handler->load('module_handler_test_added'));
    $this->assertTrue(function_exists('module_handler_test_added_helper'), 'Function exists after being loaded.');
    $this->assertTrue($module_handler->load('module_handler_test_added'));

    $this->assertFalse($module_handler->load('module_handler_test_dne'), 'Non-existent modules returns false.');
  }
$this->moduleHandler = \Drupal::moduleHandler();
    }
    return $this->moduleHandler;
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $result = TRUE;
    try {
      $result_hook = $this->getModuleHandler()->invokeAll('migrate_prepare_row', [$row$this$this->migration]);
      $result_named_hook = $this->getModuleHandler()->invokeAll('migrate_' . $this->migration->id() . '_prepare_row', [$row$this$this->migration]);
      // We will skip if any hook returned FALSE.       $skip = ($result_hook && in_array(FALSE, $result_hook)) || ($result_named_hook && in_array(FALSE, $result_named_hook));
      $save_to_map = TRUE;
    }
    catch (MigrateSkipRowException $e) {
      $skip = TRUE;
      $save_to_map = $e->getSaveToMap();
      if ($message = trim($e->getMessage())) {
        $this->idMap->saveMessage($row->getSourceIdValues()$message, MigrationInterface::MESSAGE_INFORMATIONAL);
      }
    }
/** * Gets the name of a provider. * * @param string $provider * The machine name of a plugin provider. * * @return string * The human-readable module name if it exists, otherwise the * machine-readable name passed. */
  protected function getProviderName($provider) {
    $list = $this->getModuleHandler()->getModuleList();
    // If the module exists, return its human-readable name.     if (isset($list[$provider])) {
      return $this->getModuleHandler()->getName($provider);
    }
    // Otherwise, return the machine name.     return $provider;
  }

  /** * Returns the module handler used. * * @return \Drupal\Core\Extension\ModuleHandlerInterface * The module handler. */
Home | Imprint | This part of the site doesn't use cookies.