'item-list']; /** @var Generator */ protected $data; /** @var ?MigrationForm */ protected $migrationForm; /** @var bool Whether to render minimal migration list items */ protected $minimal = true; /** * Create a new migration list * * @param Generator|array $data * * @param ?MigrationForm $form */ public function __construct($data, MigrationForm $form = null) { parent::__construct($data); $this->migrationForm = $form; } /** * Set whether to render minimal migration list items * * @param bool $minimal * * @return $this */ public function setMinimal(bool $minimal): self { $this->minimal = $minimal; return $this; } /** * Get whether to render minimal migration list items * * @return bool */ public function isMinimal(): bool { return $this->minimal; } protected function getItemClass(): string { if ($this->isMinimal()) { return MigrationListItem::class; } return MigrationFileListItem::class; } protected function assemble(): void { $itemClass = $this->getItemClass(); if (! $this->isMinimal()) { $this->getAttributes()->add('class', 'file-list'); } /** @var DbMigrationHook $data */ foreach ($this->data as $data) { /** @var MigrationFileListItem|MigrationListItem $item */ $item = new $itemClass($data, $this); if ($item instanceof MigrationListItem && $this->migrationForm) { $migrateButton = $this->migrationForm->createElement( 'submit', sprintf('migrate-%s', $data->getModuleName()), [ 'required' => false, 'label' => $this->translate('Migrate'), 'title' => sprintf( $this->translatePlural( 'Migrate %d pending migration', 'Migrate all %d pending migrations', $data->count() ), $data->count() ) ] ); $mm = MigrationManager::instance(); if ($data->isModule() && $mm->hasMigrations(DbMigrationHook::DEFAULT_MODULE)) { $migrateButton->getAttributes() ->set('disabled', true) ->set( 'title', $this->translate( 'Please apply all the pending migrations of Icinga Web first or use the apply all' . ' button instead.' ) ); } $this->migrationForm->registerElement($migrateButton); $item->setMigrateButton($migrateButton); } $this->addHtml($item); } if ($this->isEmpty()) { $this->setTag('div'); $this->addHtml(new EmptyStateBar(t('No items found.'))); } } }