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
[4.0] Media fields accessibility - second try #27712
Merged
Merged
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
3d05001
add param for alt
astridx 28c8312
change fieldtype
astridx 018b314
accessiblemedia
astridx 7d9a661
layout
astridx 1e42c33
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 79b829d
correction
astridx fa42562
frontend alt text dispay correction
astridx 89a45c9
change layout
astridx 59791c8
fixes
astridx 6b65939
language fix
astridx f31c5d9
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 97b8319
delete param in plugin, because we want to force the use. It should n…
astridx f1f8f69
move formsource because it belongs to the field and not to the plugin
astridx c7ef342
change layout
astridx 88f9ab3
make field use media variables
astridx ba554b8
correciton
astridx edf38f6
correciton
astridx b5b072f
correction
astridx f5c302c
language files
astridx 5a2a4b0
add parents variables
astridx 75aa70f
Merge branch '4.0-dev' into media2
astridx 480e655
https://github.com/joomla/joomla-cms/pull/27746
astridx 08b9709
wip
astridx 89c30e3
conflict
astridx f4b3b0b
change code form layout to field
astridx 19e4ed1
correction
astridx 572a900
wip
astridx 1f67de2
wip
astridx 6828c48
wip
astridx 3c8a1f4
wip
astridx bc499c5
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 4da9620
old values
astridx cb3b9bd
wip
astridx 0f07ac8
wip
astridx aec816f
wip
astridx c57fb9f
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx fc3c671
cs
astridx 473afb3
Remove outside of else section and remove empty else section.
astridx 59811e1
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 8d378b0
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 8327138
nun aber
astridx a7d8f8a
try
astridx c4d5130
wip
astridx f3b19a0
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 561ecaa
redo
astridx 468e721
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx f42dbae
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 53b4698
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 6e0fb6d
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 6618d64
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx a9ff995
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 272ab32
wip
astridx e8fc9d5
add comment
astridx 4a24cb4
add comment
astridx aa900db
cs
astridx 3973cf8
extend check
astridx 3188685
conflict
astridx 8294355
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx 7b4068e
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into m…
astridx File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Site | ||
* @subpackage Layout | ||
* | ||
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
extract($displayData); | ||
|
||
$form = $forms[0]; | ||
|
||
$formfields = $form->getGroup(''); | ||
?> | ||
|
||
<div class="subform-wrapper"> | ||
<?php foreach ($formfields as $field) : ?> | ||
<?php echo $field->renderField(); ?> | ||
<?php endforeach; ?> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\CMS\Form\Field; | ||
|
||
\defined('JPATH_PLATFORM') or die; | ||
|
||
use Joomla\CMS\Filesystem\Path; | ||
use Joomla\CMS\Form\Field\SubformField; | ||
|
||
/** | ||
* The Field to load the form inside current form | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class AccessiblemediaField extends SubformField | ||
{ | ||
/** | ||
* The form field type. | ||
* | ||
* @var string | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $type = 'Accessiblemedia'; | ||
|
||
/** | ||
* The preview. | ||
* | ||
* @var string | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $preview; | ||
|
||
/** | ||
* The directory. | ||
* | ||
* @var string | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $directory; | ||
|
||
/** | ||
* The previewWidth. | ||
* | ||
* @var integer | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $previewWidth; | ||
|
||
/** | ||
* The previewHeight. | ||
* | ||
* @var integer | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $previewHeight; | ||
|
||
/** | ||
* Layout to render | ||
* | ||
* @var string | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $layout; | ||
|
||
/** | ||
* Method to get certain otherwise inaccessible properties from the form field object. | ||
* | ||
* @param string $name The property name for which to get the value. | ||
* | ||
* @return mixed The property value or null. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function __get($name) | ||
{ | ||
switch ($name) | ||
{ | ||
case 'directory': | ||
case 'preview': | ||
case 'previewHeight': | ||
case 'previewWidth': | ||
return $this->$name; | ||
} | ||
|
||
return parent::__get($name); | ||
} | ||
|
||
/** | ||
* Method to set certain otherwise inaccessible properties of the form field object. | ||
* | ||
* @param string $name The property name for which to set the value. | ||
* @param mixed $value The value of the property. | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function __set($name, $value) | ||
{ | ||
switch ($name) | ||
{ | ||
case 'directory': | ||
case 'preview': | ||
$this->$name = (string) $value; | ||
break; | ||
|
||
case 'previewHeight': | ||
case 'previewWidth': | ||
$this->$name = (int) $value; | ||
break; | ||
|
||
default: | ||
parent::__set($name, $value); | ||
} | ||
} | ||
|
||
/** | ||
* Method to attach a Form object to the field. | ||
* | ||
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object. | ||
* @param mixed $value The form field value to validate. | ||
* @param string $group The field name group control value. | ||
* | ||
* @return boolean True on success. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function setup(\SimpleXMLElement $element, $value, $group = null) | ||
{ | ||
json_decode($value); | ||
|
||
// Check if value is a valid JSON string. | ||
if ($value !== '' && json_last_error() !== JSON_ERROR_NONE) | ||
{ | ||
/** | ||
* If the value is not empty and is not a valid JSON string, | ||
* it is most likely a custom field created in Joomla 3 and | ||
* the value is a string that contains the file name. | ||
*/ | ||
if (file_exists(JPATH_ROOT . '/' . $value)) | ||
{ | ||
$value = '{"imagefile":"' . $value . '","alt_text":""}'; | ||
} | ||
else | ||
{ | ||
$value = ''; | ||
} | ||
} | ||
|
||
if (!parent::setup($element, $value, $group)) | ||
{ | ||
return false; | ||
} | ||
|
||
$this->directory = (string) $this->element['directory']; | ||
$this->preview = (string) $this->element['preview']; | ||
$this->previewHeight = isset($this->element['preview_height']) ? (int) $this->element['preview_height'] : 200; | ||
$this->previewWidth = isset($this->element['preview_width']) ? (int) $this->element['preview_width'] : 200; | ||
|
||
$xml = <<<XML | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<form> | ||
<fieldset | ||
name="accessiblemedia" | ||
label="JLIB_FORM_FIELD_PARAM_ACCESSIBLEMEDIA_LABEL" | ||
> | ||
<field | ||
name="imagefile" | ||
type="media" | ||
label="JLIB_FORM_FIELD_PARAM_ACCESSIBLEMEDIA_PARAMS_IMAGEFILE_LABEL" | ||
directory="$this->directory" | ||
preview="$this->preview" | ||
preview_width="$this->previewWidth" | ||
preview_height="$this->previewHeight" | ||
/> | ||
|
||
<field | ||
name="alt_text" | ||
type="text" | ||
label="JLIB_FORM_FIELD_PARAM_ACCESSIBLEMEDIA_PARAMS_ALT_TEXT_LABEL" | ||
/> | ||
</fieldset> | ||
</form> | ||
XML; | ||
$this->formsource = $xml; | ||
|
||
$this->layout = 'joomla.form.field.media.accessiblemedia'; | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,81 @@ | |
|
||
defined('_JEXEC') or die; | ||
|
||
use Joomla\CMS\Form\Form; | ||
|
||
/** | ||
* Fields Media Plugin | ||
* | ||
* @since 3.7.0 | ||
*/ | ||
class PlgFieldsMedia extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin | ||
{ | ||
/** | ||
* Transforms the field into a DOM XML element and appends it as a child on the given parent. | ||
* | ||
* @param stdClass $field The field. | ||
* @param DOMElement $parent The field node parent. | ||
* @param Form $form The form. | ||
* | ||
* @return DOMElement | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function onCustomFieldsPrepareDom($field, DOMElement $parent, Form $form) | ||
{ | ||
$fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); | ||
|
||
if (!$fieldNode) | ||
{ | ||
return $fieldNode; | ||
} | ||
|
||
$fieldNode->setAttribute('type', 'accessiblemedia'); | ||
|
||
return $fieldNode; | ||
} | ||
|
||
/** | ||
* Before prepares the field value. | ||
* | ||
* @param string $context The context. | ||
* @param \stdclass $item The item. | ||
* @param \stdclass $field The field. | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOAY_VERSION__ | ||
*/ | ||
public function onCustomFieldsBeforePrepareField($context, $item, $field) | ||
{ | ||
// Check if the field should be processed by us | ||
if (!$this->isTypeSupported($field->type)) | ||
{ | ||
return; | ||
} | ||
|
||
// Check if the field value is an old (string) value | ||
$field->apivalue = $this->checkValue($field->value); | ||
} | ||
|
||
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. Doc block is missing @astridx 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. Thanks @zero-24 . Out of laziness, I often use the Joomla internal cs-checker and this doesn't show such errors. |
||
/** | ||
* Before prepares the field value. | ||
* | ||
* @param string $value The value to check. | ||
* | ||
* @return array The checked value | ||
* | ||
* @since __DEPLOAY_VERSION__ | ||
*/ | ||
private function checkValue($value) | ||
{ | ||
json_decode($value); | ||
|
||
if (json_last_error() === JSON_ERROR_NONE) | ||
{ | ||
return (array) json_decode($value, true); | ||
} | ||
|
||
return array('imagefile' => $value, 'alt_text' => ''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be in the plugin.
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.
I tried it that way.
Then the picture of an in the past created field is only displayed correctly in the front. It is not displayed in the back end if you edit an article.
What am I doing wrong?
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.
Not sure. But this will need to be fixed somehow :/
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.
So that the PR works again I fixed it in the field again. I see no way to influence the value of the field in the custom field - just the markup. If someone sees a possibility: I would be happy to learn. I also think that this should be done better in Custom Field.