-
Notifications
You must be signed in to change notification settings - Fork 36
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -38,6 +39,13 @@ class InstallationWizardForm extends FormBase { | |
*/ | ||
protected $useAjax = TRUE; | ||
|
||
/** | ||
* The module handler. | ||
* | ||
* @var \Drupal\Core\Extension\ModuleHandlerInterface | ||
*/ | ||
protected $moduleHandler; | ||
|
||
/** | ||
* Current step. | ||
* | ||
|
@@ -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; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return new static( | ||
$container->get('class_resolver') | ||
$container->get('class_resolver'), | ||
$container->get('module_handler') | ||
); | ||
} | ||
|
||
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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">' . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @saurabhtripathics - we should use a twig file to theme the title markup. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>'; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done