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

Replace required asterisk with text label. #1039

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions admin/themes/default/css/sass/components/_inputs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,15 @@ label {
}
}

.required:after {
content: "*";
.required-label {
background-color: #eee;
border-radius: 2px;
display: block;
width: fit-content;
padding: 0 .25rem;
font-weight: normal;
font-size: 12px;
margin: 3px 0;
}

textarea {
Expand Down
11 changes: 9 additions & 2 deletions admin/themes/default/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions admin/themes/default/css/style.css.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion admin/themes/default/item-types/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<section class="seven columns alpha">
<fieldset id="type-information">
<legend><?php echo __('Item Type Information'); ?></legend>
<p class='explanation'>* <?php echo __('required field'); ?></p>

<div class="field">
<?php echo $this->form->getElement(Omeka_Form_ItemTypes::NAME_ELEMENT_ID); ?>
Expand Down
1 change: 0 additions & 1 deletion admin/themes/default/users/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
?>
<form method="post">
<section class="seven columns alpha">
<p class='explanation'>* <?php echo __('required field'); ?></p>
<?php echo $this->form; ?>
<?php fire_plugin_hook('admin_users_form', array('form' => $form, 'view' => $this)); ?>
</section>
Expand Down
1 change: 0 additions & 1 deletion admin/themes/default/users/change-password.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
?>
<form id="change-password" method="post">
<section class="seven columns alpha">
<p class='explanation'>* <?php echo __('required field'); ?></p>
<?php echo $this->form; ?>
</section>
<section class="three columns omega">
Expand Down
1 change: 0 additions & 1 deletion admin/themes/default/users/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
?>
<form method="post">
<section class="seven columns alpha">
<p class='explanation'>* <?php echo __('required field'); ?></p>
<?php echo $this->form; ?>
</section>
<section class="three columns omega">
Expand Down
2 changes: 1 addition & 1 deletion admin/themes/default/users/forgot-password.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<form method="post" accept-charset="utf-8">
<div class="field">
<div class="inputs six columns offset-by-one omega">
<?php echo $this->formText('email', @$_POST['email']); ?>
<?php echo $this->formText('email', @$_POST['email'], array('required' => 'required')); ?>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion application/forms/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function init()
'ViewHelper',
array('Errors', array('class' => 'error')),
array(array('input' => 'HtmlTag'), array('tag' => 'div', 'class' => 'inputs')),
array('Label', array('tag' => 'div', 'tagClass' => 'field-meta')),
array('Label', array('tag' => 'div', 'tagClass' => 'field-meta', 'escape' => false, 'requiredSuffix' => sprintf('<span class="required-label">%s</span>', __('required field')))),
array('HtmlTag', array('tag' => 'div', 'class' => 'field'))
);

Expand Down
5 changes: 4 additions & 1 deletion application/libraries/Omeka/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ public function getDefaultElementDecorators()
// <input type="submit" />
// </div>

$defaultLabelOptions = array('placement' => 'prepend', 'tag' => 'div', 'tagClass' => 'two columns alpha', 'requiredSuffix' => sprintf('<span class="required-label">%s</span>', __('required field')));
$defaultLabel = new Omeka_Form_Decorator_DefaultLabel($defaultLabelOptions);

return array(
array('Description', array('tag' => 'p', 'class' => 'explanation', 'escape' => false)),
'ViewHelper',
array('Errors', array('class' => 'error')),
array(array('InputsTag' => 'HtmlTag'), array('tag' => 'div', 'class' => 'inputs five columns omega')),
array('Label', array('tag' => 'div', 'tagClass' => 'two columns alpha')),
$defaultLabel,
array(array('FieldTag' => 'HtmlTag'), array('tag' => 'div', 'class' => 'field'))
);
}
Expand Down
177 changes: 177 additions & 0 deletions application/libraries/Omeka/Form/Decorator/DefaultLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
/**
* Omeka
*
* @copyright 2016-present Corporation for Digital Scholarship,
* 2008-2016 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/

/**
* Custom decorator for default labels
*
* @package Omeka\Form\Decorator
*/
class Omeka_Form_Decorator_DefaultLabel extends Zend_Form_Decorator_Label
{
/**
* Get label to render
*
* @return string
*/
public function getLabel()
{
if (null === ($element = $this->getElement())) {
return '';
}

$label = (string) $element->getLabel();
$label = trim($label);

if (empty($label)) {
return '';
}

return $label;
}

/**
* Return label with required suffix or prefix.
* Includes custom default suffix.
*
* @return string
*/
public function handleRequired($label, $element) {
$optPrefix = $this->getOptPrefix();
$optSuffix = $this->getOptSuffix();
$reqPrefix = $this->getReqPrefix();
$reqSuffix = $this->getReqSuffix();

if (!empty($label)) {
if ($element->isRequired()) {
$label = $reqPrefix . $label . $reqSuffix;
} else {
$label = $optPrefix . $label . $optSuffix;
}
}

return $label;
}

/**
* Render a label
*
* @param string $content
* @return string
*/
public function render($content)
{
$element = $this->getElement();
$view = $element->getView();
if (null === $view) {
return $content;
}

$label = $this->getLabel();
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$tag = $this->getTag();
$tagClass = $this->getTagClass();
$id = $this->getId();
$class = $this->getClass();
$options = $this->getOptions();


if (empty($label) && empty($tag)) {
return $content;
}

if (!empty($label)) {
$options['class'] = $class;
$label = trim($label);
// Give formLabel already escaped label content alongside
// non-escaped required markup.
$formLabelOptions = $options;
$formLabelOptions['escape'] = false;

// Escape the label, but not the required markup.
if (!isset($options['escape']) || ($options['escape'] == true)){
$label = $view->escape($label);
}
$label = $this->handleRequired($label, $element);

switch ($placement) {
case self::IMPLICIT:
// Break was intentionally omitted

case self::IMPLICIT_PREPEND:
$formLabelOptions['disableFor'] = true;

$label = $view->formLabel(
$element->getFullyQualifiedName(),
$label . $separator . $content,
$formLabelOptions
);
break;

case self::IMPLICIT_APPEND:
$formLabelOptions['disableFor'] = true;

$label = $view->formLabel(
$element->getFullyQualifiedName(),
$content . $separator . $label,
$formLabelOptions
);
break;

case self::APPEND:
// Break was intentionally omitted

case self::PREPEND:
// Break was intentionally omitted

default:
$label = $view->formLabel(
$element->getFullyQualifiedName(),
$label,
$formLabelOptions
);
break;
}
} else {
$label = '&#160;';
}

if (null !== $tag) {
require_once 'Zend/Form/Decorator/HtmlTag.php';
$decorator = new Zend_Form_Decorator_HtmlTag();
if (null !== $this->_tagClass) {
$decorator->setOptions(array('tag' => $tag,
'id' => $id . '-label',
'class' => $tagClass));
} else {
$decorator->setOptions(array('tag' => $tag,
'id' => $id . '-label'));
}

$label = $decorator->render($label);
}

switch ($placement) {
case self::APPEND:
return $content . $separator . $label;

case self::PREPEND:
return $label . $separator . $content;

case self::IMPLICIT:
// Break was intentionally omitted

case self::IMPLICIT_PREPEND:
// Break was intentionally omitted

case self::IMPLICIT_APPEND:
return $label;
}
}
}