getProjectTitle example


  public function __construct($source$root) {
    $this->source = $source;
    $this->root = $root;
    $this->name = self::getProjectName($source);
    $this->title = self::getProjectTitle($source);
  }

  /** * Returns an Updater of the appropriate type depending on the source. * * If a directory is provided which contains a module, will return a * ModuleUpdater. * * @param string $source * Directory of a Drupal project. * @param string $root * The root directory under which the project will be copied to if it's a * new project. Usually this is the app root (the directory in which the * Drupal site is installed). * * @return \Drupal\Core\Updater\Updater * A new Drupal\Core\Updater\Updater object. * * @throws \Drupal\Core\Updater\UpdaterException */
$project_location = $directory . '/' . $project;
    try {
      $updater = Updater::factory($project_location$this->root);
    }
    catch (\Exception $e) {
      $this->messenger()->addError($e->getMessage());
      return;
    }

    try {
      $project_title = Updater::getProjectTitle($project_location);
    }
    catch (\Exception $e) {
      $this->messenger()->addError($e->getMessage());
      return;
    }

    if (!$project_title) {
      $this->messenger()->addError($this->t('Unable to determine %project name.', ['%project' => $project]));
    }

    if ($updater->isInstalled()) {
      
class UpdaterTest extends KernelTestBase {

  /** * Tests project and child project showing correct title. * * @see https://drupal.org/node/2409515 */
  public function testGetProjectTitleWithChild() {
    // Get the project title from its directory. If it can't find the title     // it will choose the first project title in the directory.     $directory = $this->root . '/core/modules/system/tests/modules/module_handler_test_multiple';
    $title = Updater::getProjectTitle($directory);
    $this->assertEquals('module handler test multiple', $title);
  }

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