install_profile_info example

/** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state$install_state = NULL) {
    $form['#title'] = $this->t('Select an installation profile');

    $profiles = [];
    $names = [];
    foreach ($install_state['profiles'] as $profile) {
      /** @var \Drupal\Core\Extension\Extension $profile */
      $details = install_profile_info($profile->getName());
      // Don't show hidden profiles. This is used by to hide the testing profile,       // which only exists to speed up test runs.       if ($details['hidden'] === TRUE && !drupal_valid_test_ua()) {
        continue;
      }
      $profiles[$profile->getName()] = $details;

      // Determine the name of the profile; default to file name if defined name       // is unspecified.       $name = $details['name'] ?? $profile->getName();
      $names[$profile->getName()] = $name;
    }
    // location.     // @todo Remove as part of https://www.drupal.org/node/2186491     $profile_list = \Drupal::service('extension.list.profile');
    assert($profile_list instanceof ProfileExtensionList);
    $profile_list->setPathname('testing_missing_dependencies', 'core/profiles/testing_missing_dependencies/testing_missing_dependencies.info.yml');

    // Requires install.inc to be able to use drupal_verify_profile.     require_once dirname(__FILE__, 7) . '/includes/install.inc';

    $info = drupal_verify_profile([
      'parameters' => ['profile' => 'testing_missing_dependencies'],
      'profile_info' => install_profile_info('testing_missing_dependencies'),
    ]);

    $message = $info['required_modules']['description']->render();
    $this->assertStringContainsString('Fictional', $message);
    $this->assertStringContainsString('Missing_module1', $message);
    $this->assertStringContainsString('Missing_module2', $message);
    $this->assertStringNotContainsString('Block', $message);
    $this->assertStringNotContainsString('Node', $message);
  }

}
require_once 'core/includes/install.inc';

    // Prime the \Drupal\Core\Extension\ExtensionList::getPathname() static     // cache with the location of the testing profile as it isn't the currently     // active profile and we don't yet have any cached way to retrieve its     // location.     // @todo Remove as part of https://www.drupal.org/node/2186491     $profile_list = \Drupal::service('extension.list.profile');
    assert($profile_list instanceof ProfileExtensionList);
    $profile_list->setPathname('testing', 'core/profiles/testing/testing.info.yml');

    $info_en = install_profile_info('testing', 'en');
    $info_nl = install_profile_info('testing', 'nl');

    $this->assertNotContains('locale', $info_en['install'], 'Locale is not set when installing in English.');
    $this->assertContains('locale', $info_nl['install'], 'Locale is set when installing in Dutch.');
  }

}
Home | Imprint | This part of the site doesn't use cookies.