Skip to content

Commit

Permalink
Context sensitive help texts for fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
haogatyp authored and claussni committed Jun 4, 2021
1 parent 2111771 commit 134b43b
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 6 deletions.
50 changes: 50 additions & 0 deletions Classes/Domain/Model/DocumentFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ class DocumentFormField extends AbstractFormElement
*/
protected $maxInputLength;

/**
* help text
*
* @var string
*/
protected $helpText = '';

/**
* @var string
*/
Expand Down Expand Up @@ -287,4 +294,47 @@ public function setDepositLicense($depositLicense): void
$this->depositLicense = $depositLicense;
}

/**
* @return string
*/
public function getHelpText(): string
{
return $this->helpText;
}

/**
* @param string $helpText
*/
public function setHelpText(string $helpText): void
{
$this->helpText = $helpText;
}

public function getHelpTextLong()
{
if ($this->helpText) {
$domDocument = new \DOMDocument();
$domDocument->loadXML("<html>".$this->helpText."</html>");
$xpath = \EWW\Dpf\Helper\XPath::create($domDocument);
$nodes = $xpath->query("//p");
if ($nodes->length > 1) {
$domDocument->firstChild->removeChild($nodes->item(0));
return str_replace(['<html>','</html>'], '', $domDocument->saveHTML());
}
}
}

public function getHelpTextShort()
{
if ($this->helpText) {
$domDocument = new \DOMDocument();
$domDocument->loadXML("<html>".$this->helpText."</html>");
$xpath = \EWW\Dpf\Helper\XPath::create($domDocument);
$nodes = $xpath->query("//p");
if ($nodes->length > 0) {
return $nodes->item(0)->nodeValue;
}
}
}

}
23 changes: 23 additions & 0 deletions Classes/Domain/Model/MetadataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ class MetadataObject extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity impl
*/
protected $orcidPersonMapping = '';

/**
* help text
*
* @var string
*/
protected $helpText = '';

/**
* Returns the name
*
Expand Down Expand Up @@ -785,4 +792,20 @@ public function setDepositLicense($depositLicense): void
{
$this->depositLicense = $depositLicense;
}

/**
* @return string
*/
public function getHelpText(): string
{
return $this->helpText;
}

/**
* @param string $helpText
*/
public function setHelpText(string $helpText): void
{
$this->helpText = $helpText;
}
}
4 changes: 4 additions & 0 deletions Classes/Helper/DocumentMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ public function getDocumentForm(Document $document, $generateEmptyFields = true)
$depositLicense = $this->depositLicenseRepository->findByUid($metadataObject->getDepositLicense());
$documentFormField->setDepositLicense($depositLicense);

$documentFormField->setHelpText($metadataObject->getHelpText());

$objectMapping = "";

preg_match_all('/([A-Za-z0-9]+:[A-Za-z0-9]+(\[.*\])*|[A-Za-z0-9:@\.]+)/', $metadataObject->getRelativeMapping(), $objectMappingPath);
Expand Down Expand Up @@ -324,6 +326,8 @@ public function getDocumentForm(Document $document, $generateEmptyFields = true)
$depositLicense = $this->depositLicenseRepository->findByUid($metadataObject->getDepositLicense());
$documentFormField->setDepositLicense($depositLicense);

$documentFormField->setHelpText($metadataObject->getHelpText());

$documentFormGroup->addItem($documentFormField);
}

Expand Down
17 changes: 14 additions & 3 deletions Configuration/TCA/tx_dpf_domain_model_metadataobject.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
'starttime' => 'starttime',
'endtime' => 'endtime',
),
'searchFields' => 'name, display_name, max_iteration, mandatory, data_type, validation, mapping, mods_extension, json_mapping, input_field, deposit_license, max_input_length, input_option_list, fill_out_service, gnd_field_uid, default_value, access_restriction_roles, consent, embargo, fis_person_mapping, fis_organisation_mapping, gnd_person_mapping, gnd_organisation_mapping, ror_mapping, zdb_mapping, unpaywall_mapping, orcid_person_mapping, object_type',
'searchFields' => 'name, display_name, max_iteration, mandatory, data_type, validation, mapping, mods_extension, json_mapping, input_field, deposit_license, max_input_length, input_option_list, fill_out_service, gnd_field_uid, default_value, access_restriction_roles, consent, embargo, fis_person_mapping, fis_organisation_mapping, gnd_person_mapping, gnd_organisation_mapping, ror_mapping, zdb_mapping, unpaywall_mapping, orcid_person_mapping, help_text, object_type',
'iconfile' => 'EXT:dpf/Resources/Public/Icons/default.gif',
),
'interface' => array(
'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, name, display_name, max_iteration, mandatory, data_type, validation, mapping, mods_extension, json_mapping, input_field, deposit_license, max_input_length, input_option_list, fill_out_service, gnd_field_uid, default_value, access_restriction_roles, consent, embargo, fis_person_mapping, fis_organisation_mapping, gnd_person_mapping, gnd_organisation_mapping, ror_mapping, zdb_mapping, unpaywall_mapping, orcid_person_mapping, object_type',
'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, name, display_name, max_iteration, mandatory, data_type, validation, mapping, mods_extension, json_mapping, input_field, deposit_license, max_input_length, input_option_list, fill_out_service, gnd_field_uid, default_value, access_restriction_roles, consent, embargo, fis_person_mapping, fis_organisation_mapping, gnd_person_mapping, gnd_organisation_mapping, ror_mapping, zdb_mapping, unpaywall_mapping, orcid_person_mapping, help_text, object_type',
),
'types' => array(
'1' => array('showitem' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, --palette--;;1, name, display_name, max_iteration, mandatory, data_type, validation, mapping, mods_extension, json_mapping, input_field, deposit_license, max_input_length, input_option_list, fill_out_service, gnd_field_uid, default_value, access_restriction_roles, consent, embargo, fis_person_mapping, fis_organisation_mapping, gnd_person_mapping, gnd_organisation_mapping, ror_mapping, zdb_mapping, unpaywall_mapping, orcid_person_mapping, object_type, --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.access, starttime, endtime'),
'1' => array('showitem' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, --palette--;;1, name, display_name, max_iteration, mandatory, data_type, validation, mapping, mods_extension, json_mapping, input_field, deposit_license, max_input_length, input_option_list, fill_out_service, gnd_field_uid, default_value, access_restriction_roles, consent, embargo, fis_person_mapping, fis_organisation_mapping, gnd_person_mapping, gnd_organisation_mapping, ror_mapping, zdb_mapping, unpaywall_mapping, orcid_person_mapping, help_text, object_type, --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.access, starttime, endtime'),
),
'palettes' => array(
'1' => array('showitem' => ''),
Expand Down Expand Up @@ -467,5 +467,16 @@
],
],
],
'help_text' => array(
'exclude' => 1,
'label' => 'LLL:EXT:dpf/Resources/Private/Language/locallang_db.xlf:tx_dpf_domain_model_metadataobject.help_text',
'config' => array(
'type' => 'text',
'cols' => 40,
'rows' => 15,
'eval' => 'trim',
'enableRichtext' => true,
),
),
),
);
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<source>Display name</source>
<target>Anzeigename</target>
</trans-unit>
<trans-unit id="help_text.description">
<source>Help text</source>
<target>Hilfe-Text</target>
</trans-unit>
<trans-unit id="fill_out_service.description" approved="yes">
<source>Fillout service</source>
<target>Fillout Service</target>
Expand Down Expand Up @@ -79,4 +83,4 @@
</trans-unit>
</body>
</file>
</xliff>
</xliff>
4 changes: 4 additions & 0 deletions Resources/Private/Language/de.locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@
<source>Display Name</source>
<target>Anzeigename</target>
</trans-unit>
<trans-unit id="tx_dpf_domain_model_metadataobject.help_text" approved="yes">
<source>Help text</source>
<target>Hilfe-Text</target>
</trans-unit>
<trans-unit id="tx_dpf_domain_model_metadataobject.embargo" approved="yes">
<source>Embargo</source>
<target>Embargo</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<trans-unit id="display_name.description">
<source>Display name</source>
</trans-unit>
<trans-unit id="help_text.description">
<source>Help text</source>
</trans-unit>
<trans-unit id="fill_out_service.description">
<source>Fillout service</source>
</trans-unit>
Expand Down Expand Up @@ -61,4 +64,4 @@
</trans-unit>
</body>
</file>
</xliff>
</xliff>
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@
<trans-unit id="tx_dpf_domain_model_metadataobject.display_name">
<source>Display Name</source>
</trans-unit>
<trans-unit id="tx_dpf_domain_model_metadataobject.help_text">
<source>Help text</source>
</trans-unit>
<trans-unit id="tx_dpf_domain_model_metadataobject.embargo">
<source>Embargo</source>
</trans-unit>
Expand Down
18 changes: 18 additions & 0 deletions Resources/Private/Partials/DocumentForm/Field.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,26 @@
</div>
</f:if>

<f:if condition="{fieldItem.helpTextLong}">
<div class="collapse" id="collapse{formPageUid}-{formGroupUid}-{groupIndex}-{fieldItem.uid}-{fieldIndex}">
<div class="alert alert-primary" role="alert">
<a class="close" href="#collapse{formPageUid}-{formGroupUid}-{groupIndex}-{fieldItem.uid}-{fieldIndex}" data-toggle="collapse" aria-label="Close">
<span aria-hidden="true">&times;</span>
</a>
<f:format.raw>{fieldItem.helpTextLong}</f:format.raw>
</div>
</div>
</f:if>

<div class="form-group">
<label for="inp_{fieldItem.uid}" data-index="{fieldIndex}" data-field="{fieldItem.uid}">{fieldItem.displayName}
<f:if condition="{fieldItem.helpTextShort}">
<a data-toggle="collapse" href="#collapse{formPageUid}-{formGroupUid}-{groupIndex}-{fieldItem.uid}-{fieldIndex}">
<span data-toggle="tooltip" title="" data-original-title="{fieldItem.helpTextShort}">
<i class="fas fa-question-circle"></i>
</span>
</a>
</f:if>
<f:if condition="{fieldItem.mandatory}">
<span class="mandatory" data-index="{fieldIndex}" data-field="{fieldItem.uid}">*</span>
</f:if>
Expand Down
6 changes: 5 additions & 1 deletion Resources/Public/CSS/kitodopublication.css
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ ul.error-files-backbutton li {
margin: 0;
}

.alert p:last-child {
margin-bottom: 0;
}

/* -- search form--------------------------------------------------- */

#tx-dpf-backoffice.document-manager .searchForm .form-group {
Expand Down Expand Up @@ -536,4 +540,4 @@ ul.error-files-backbutton li {
padding: 0px 0px 0px 3px;
}
}
/* EOF */
/* EOF */
1 change: 1 addition & 0 deletions ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ CREATE TABLE tx_dpf_domain_model_metadataobject (
input_option_list int(11) unsigned default '0',
default_value text NOT NULL,
fill_out_service varchar(255) DEFAULT '' NOT NULL,
help_text text NOT NULL,
backend_only tinyint(1) unsigned DEFAULT '0' NOT NULL,
access_restriction_roles varchar(255) DEFAULT '' NOT NULL,
consent tinyint(1) unsigned DEFAULT '0' NOT NULL,
Expand Down

0 comments on commit 134b43b

Please sign in to comment.