Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACMS-677: Add side navigation and field title markup #676

Merged
merged 3 commits into from
Mar 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 74 additions & 2 deletions modules/acquia_cms_tour/src/Form/InstallationWizardForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\acquia_cms_tour\Form;

use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
Expand Down Expand Up @@ -38,6 +39,13 @@ class InstallationWizardForm extends FormBase {
*/
protected $useAjax = TRUE;

/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;

/**
* Current step.
*
Expand All @@ -64,17 +72,21 @@ public function getFormId() {
*
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
* The class resolver.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(ClassResolverInterface $class_resolver) {
public function __construct(ClassResolverInterface $class_resolver, ModuleHandlerInterface $module_handler) {
$this->classResolver = $class_resolver;
$this->moduleHandler = $module_handler;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saurabhtripathics - do we really need it? We should return the full module details from ACMSDashboardBase class, and just utilize it here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('class_resolver')
$container->get('class_resolver'),
$container->get('module_handler')
);
}

Expand Down Expand Up @@ -356,11 +368,71 @@ public function stepForm(array &$form, FormStateInterface $form_state) {
$formController = $this->steps[$this->currentStep];
$sections = \array_flip(self::SECTIONS);
$key = $sections[$formController];
$form['title_markup'] = [
'#type' => 'markup',
'#markup' => $this->getTitleMarkup($key, ($this->currentStep) + 1),
];
$form['sidebar_markup'] = [
'#type' => 'markup',
'#markup' => $this->getSideBarMarkup($sections, ($this->currentStep) + 1),
];
$form = $this->classResolver->getInstanceFromDefinition($formController)->buildForm($form, $form_state);
// Change details to fieldset for all form.
$form[$key]['#type'] = 'fieldset';
unset($form[$key]['actions']);
return $form;
}

/**
* Helper method for adding sidebar markup.
*
* @param array $sections
* The module classes.
* @param int $current_step
* The forms current step.
*
* @return string
* The render array defining the markup of the sidebar.
*/
public function getSideBarMarkup(array $sections, int $current_step) {
$sno = 0;
$markup = '<div class="tour_sidebar">';
foreach ($sections as $module) {
if ($this->moduleHandler->moduleExists($module)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saurabhtripathics - We should use the modules defined by individual controllers. Also, this markup should use getSteps method to display the steps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

$sno++;
if ($sno == $current_step) {
$current_class = 'current_step';
}
else {
$current_class = 'item-';
}
$module_name = $this->moduleHandler->getName($module);
$markup .= '<div class = ' . $current_class . ' id = ' . $module . '>' .
$sno . ' ' . $module_name .
'<div class = "status-icon">icon</div></div>';
}
}
$markup .= '</div>';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saurabhtripathics - We should try to avoid generating HTML here, it should be using a twig

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return $markup;

}

/**
* Helper method for adding title markup.
*
* @param string $module
* The module machine name.
* @param int $current_step
* The forms current step.
*
* @return string
* The render array defining the markup of the title.
*/
public function getTitleMarkup(string $module, int $current_step) {
$module_name = $this->moduleHandler->getName($module);
return '<div class="title_markup"><div id="main-title">Acquia CMS Installation Wizard</div><div class="configure-markup">' .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saurabhtripathics - we should use a twig file to theme the title markup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

$current_step . '. Configure ' . $module_name .
'</div><span class="req-markup">Fields marked <span id = "astrick">*</span> are required</span></span></div>';
}

}