Skip to content

Commit

Permalink
Merge branch '4.x' into g0.140-BringImporterShareToStandard
Browse files Browse the repository at this point in the history
  • Loading branch information
laceysanderson authored Jan 29, 2025
2 parents b41a408 + 547d8b6 commit c203d86
Show file tree
Hide file tree
Showing 22 changed files with 1,532 additions and 894 deletions.
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
<?php

/**
* @file
* Controller to display a dashboard page that houses links and descriptions
* to configuration pages.
*/

namespace Drupal\trpcultivate_phenotypes\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class definition TripalCultivatePhenotypesSettingsController.
*
* Controller to display a dashboard page that houses links and descriptions
* to configuration pages.
*/
class TripalCultivatePhenotypesSettingsController extends ControllerBase {

/**
* Returns a markup of details (fieldset) where the
* the title of the element is the configuration section and
* expanding each will reveal a short description.
* Module hander service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $module_handler;

/**
* Constructor.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(ModuleHandlerInterface $module_handler) {
$this->module_handler = $module_handler;
}

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

/**
* Provides an administrative list of phenotypes configuration pages.
*
* @return array
* A render array consisting of a details element for each configuration
* page where the title is the configuration section and the contents
* include a short description plus a link.
*/
public function loadPage() {
// Quick enabled or disabled status of sub-phenotypes modules
// and report to dashboard.
$moduleHandler = \Drupal::service('module_handler');
// Quick enabled or disabled status of sub-phenotypes modules and report
// to dashboard.
$status_message = 'Tripal Cultivate Phenotypes Modules Status: ';

foreach(['trpcultivate_phenoshare', 'trpcultivate_phenocollect'] as $m) {
$is_enabled = ($moduleHandler->moduleExists($m)) ? 'is enabled' : 'is disabled';
foreach (['trpcultivate_phenoshare', 'trpcultivate_phenocollect'] as $m) {
$is_enabled = ($this->module_handler->moduleExists($m)) ? 'is enabled' : 'is disabled';
$status_message .= '*' . $m . ' ' . $is_enabled . ' ';
}

$url = Url::fromUri('internal:/admin/modules');
$link = Link::fromTextAndUrl('Manage Modules', $url)
->toString();

$this->messenger()->addStatus($this->t($status_message . '- @manage', ['@manage' => $link]));

$this->messenger()->addStatus($status_message . ' - ' . $link);

// Describe R Rules configuration:
$url = Url::fromRoute('trpcultivate_phenotypes.settings_r');
Expand Down Expand Up @@ -90,4 +116,5 @@ public function loadPage() {

return $element;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$link_to_docs = Link::fromTextAndUrl($this->t('Tripal 4 User Guide'), $url)
->toString();

$placeholder_values = [
'@tripaljobs' => $link_to_jobs,
'@tripaldocs' => $link_to_docs,
];
$config_warning = $this->t('Tripal Cultivate Phenotypes module requires controlled vocabulary terms and genus records
used for creating terms and genus-ontology module configuration. If you already know how to execute a Tripal Job,
please proceed with the Tripal Job Id number for Tripal Job titled: Tripal Cultivate Phenotypes: Install Ontology and Terms
(@tripaljobs), otherwise, please visit @tripaldocs to learn more about Tripal Jobs.', ['@tripaljobs' => $link_to_jobs, '@tripaldocs' => $link_to_docs]);
(@tripaljobs), otherwise, please visit @tripaldocs to learn more about Tripal Jobs.', $placeholder_values);

$this->messenger()->addWarning($config_warning);
return $form;
Expand Down Expand Up @@ -325,9 +329,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// Render each term as autocomplete field element.
foreach ($this->config_vars['terms'] as $config => $prop) {
// Field description.
$describe = $this->t($prop['help_text']);
$describe = $prop['help_text'];
// Field placeholder and title text.
$placeholder = $title = $this->t(ucwords($prop['name']));
$placeholder = $title = ucwords($prop['name']);
// Field default value.
$config_value = $this->service_terms->getTermId($config);
$default_value = ChadoCVTermAutocompleteController::formatCVterm($config_value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<?php

/**
* @file
* Construct form to manage and configure R Transformation rules.
*/

namespace Drupal\trpcultivate_phenotypes\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
* Class definition TripalCultivatePhenotypesRSettingsForm.
*
* Construct form to manage and configure R Transformation rules.
*/
class TripalCultivatePhenotypesRSettingsForm extends ConfigFormBase {
const SETTINGS = 'trpcultivate_phenotypes.settings';

/**
* {@inheritdoc}
*/
Expand All @@ -30,26 +27,26 @@ protected function getEditableConfigNames() {
return [
static::SETTINGS,
];
}
/**
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config(static::SETTINGS);
$config_r = 'trpcultivate.phenotypes.r_config.';

$form['description'] = [
'#markup' => $this->t('Tripal Cultivate Phenotypes supports R language for statistical computing by providing
syntactically valid version of trait or values. Use R Transformation Rules configuration page to define
standard transformation rules to apply to trait or string when converting to R version.')
syntactically valid version of trait or values. Use R Transformation Rules configuration page to define
standard transformation rules to apply to trait or string when converting to R version.'),
];

$form['words'] = [
'#type' => 'textarea',
'#title' => $this->t('List of words to remove'),
'#default_value' => implode(',', $config->get($config_r . 'words')),
'#description' => $this->t('Separate each word entry with a comma character.
'#description' => $this->t('Separate each word entry with a comma character.
Words must at least be 2 characters or more.'),
'#required' => TRUE,
];
Expand All @@ -58,7 +55,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'textarea',
'#title' => $this->t('List of special characters to remove'),
'#default_value' => implode(',', $config->get($config_r . 'chars')),
'#description' => $this->t('Separate each character entry with a comma character.
'#description' => $this->t('Separate each character entry with a comma character.
Characters must be 1 character only.'),
'#required' => TRUE,
];
Expand All @@ -67,12 +64,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'textarea',
'#title' => $this->t('Match word and replace with'),
'#default_value' => implode(',', $config->get($config_r . 'replace')),
'#description' => $this->t('Separate match and replace pairs with a comma character.
'#description' => $this->t('Separate match and replace pairs with a comma character.
Use match = replace pattern for each combination.'),
'#required' => TRUE,
];



return parent::buildForm($form, $form_state);
}

Expand All @@ -82,33 +78,33 @@ public function buildForm(array $form, FormStateInterface $form_state) {
public function validateForm(array &$form, FormStateInterface $form_state) {
// Words: words must be at least 2 characters long.
if ($words = $form_state->getValue('words')) {
foreach(explode(',', $words) as $word) {
foreach (explode(',', $words) as $word) {
if (empty($word) || !preg_match('/\w{2,}/', $word)) {
$form_state->setErrorByName('word', $this->t('Could not save rule.
Empty or invalid word: @word added to the list.', ['@word' => $word]));
}
}
}

// Special characters: 1 character only, excluding comma symbol since
// it is used as delimiter.
if ($chars = $form_state->getValue('chars')) {
foreach(explode(',', $chars) as $char) {
foreach (explode(',', $chars) as $char) {
if (empty($char) || $char == ',' || !preg_match('/\W{1}/', $char)) {
$form_state->setErrorByName('chars', $this->t('Could not save rule.
Empty or invalid special characters: @char added to the list.', ['@char' => $char]));
Empty or invalid special characters: @char added to the list.', ['@char' => $char]));
}
}
}

// Match and replace: match = replace pattern, excluding comma symbol since
// it is used as delimiter.
if ($replaces = $form_state->getValue('replace')) {
foreach(explode(',', $replaces) as $replace) {
foreach (explode(',', $replaces) as $replace) {
if (empty($replace) || !preg_match('/^[^,]+\s{1}[=]\s{1}[^,]+$/', $replace)) {
$form_state->setErrorByName('replace', $this->t('Could not save rule.
Empty or invalid match and replace: @replace added to the list.', ['@replace' => $replace]));
}
$form_state->setErrorByName('replace', $this->t('Could not save rule.
Empty or invalid match and replace: @replace added to the list.', ['@replace' => $replace]));
}
}
}
}
Expand All @@ -118,8 +114,8 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config_r = 'trpcultivate.phenotypes.r_config.';
// Configuration in field are string, convert to array to match

// Configuration in field are string, convert to array to match
// configuration schema data type.
$this->configFactory->getEditable(static::SETTINGS)
->set($config_r . 'words', explode(',', $form_state->getValue('words')))
Expand All @@ -129,4 +125,5 @@ public function submitForm(array &$form, FormStateInterface $form_state) {

return parent::submitForm($form, $form_state);
}
}

}
Loading

0 comments on commit c203d86

Please sign in to comment.