Skip to content

Commit

Permalink
Handle errors better in the front end
Browse files Browse the repository at this point in the history
This commit makes sure link and text is still readable.
It also propagrate the error flag for each language into the parent
field.
  • Loading branch information
nitriques committed Jun 21, 2017
1 parent 55f8a10 commit 294e1e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion assets/multilingual_oembed_field.publish.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@

.field-multilingual-oembed .invalid .tab-panel label > div > i {
color: #a9a9a9;
}
}

.field-multilingual-oembed .invalid .container span {
color: #222;
}

.field-multilingual-oembed .invalid .container a {
color: #3f69a5;
}
16 changes: 15 additions & 1 deletion fields/field.multilingual_oembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@ public function displayPublishPanel(&$wrapper, $data = null, $flagWithError = nu
$all_langs = FLang::getAllLangs();
$langs = FLang::getLangs();

$errors = !$flagWithError ? array() : array_reduce(explode('.', $flagWithError), function ($carry, $item) {
$matches = array();
if (preg_match('/\[([a-z]+)\] (.+)/', $item, $matches) === 1) {
$carry[trim($matches[1])] = trim($matches[2]);
}
return $carry;
}, array());

$wrapper->setAttribute('class', $wrapper->getAttribute('class') . ' field-multilingual field-oembed field-multilingual-oembed');
$container = new XMLElement('div', null, array('class' => 'container'));

Expand Down Expand Up @@ -514,7 +522,13 @@ public function displayPublishPanel(&$wrapper, $data = null, $flagWithError = nu
'thumbnail_url' => $data["thumbnail_url-$lc"],
'driver' => $data["driver-$lc"]
);
parent::displayPublishPanel($div, $translatedData, false, $fieldnamePrefix, $fieldnamePostfix . "[$lc]");
parent::displayPublishPanel(
$div,
$translatedData,
!isset($errors[$lc]) ? null : $errors[$lc],
$fieldnamePrefix,
$fieldnamePostfix . "[$lc]"
);
$container->appendChild($div);
}
$this->set('label', $label_text);
Expand Down

0 comments on commit 294e1e9

Please sign in to comment.