-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
Added frontend_type color #2945
Merged
Merged
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
a6d9dfa
Added frontend_type color
fballiano 48b8a8e
fixed link to PR
fballiano ebc0c69
Removed maxlength
fballiano d268b75
Added support for with_hash
fballiano 526bb4e
Added support for with_hash
fballiano a7a2b93
Improvements (#6)
justinbeaty a54a86a
formatting
fballiano e6f0e6a
translations
fballiano 94e3aba
translations lowercase
fballiano 1c455ee
Merge branch '1.9.4.x' into frontend_type_color
fballiano 3fefb18
Added backend model with validation
fballiano a15916f
Default backend model
fballiano 159d1c6
Merge branch '1.9.4.x' into frontend_type_color
fballiano 7351f5f
Added getBackendClass() method (#7)
sreichel 7cfd800
doc
fballiano 7b3c162
doc
fballiano 38656dc
Update adminhtml/config (#8)
justinbeaty 003ae58
Whitespace + helper outside foreach
fballiano 3ddf5d4
Merge branch '1.9.4.x' into frontend_type_color
fballiano 41a6db9
CSfix
fballiano 535c02e
Merge branch 'frontend_type_color' of github.com:fballiano/openmage i…
fballiano d5dba71
Topic pr 2945 - backend validation (#9)
justinbeaty 7201041
removed line
fballiano 9724fcb
Merge branch '1.9.4.x' into frontend_type_color
sreichel ad626dc
Merge branch '1.9.4.x' into frontend_type_color
fballiano 1fd0e08
Suggestions by justing, adding color also for products attributes
fballiano 116b4f8
Revert "Suggestions by justing, adding color also for products attrib…
fballiano accc6bc
Merge branch '1.9.4.x' into frontend_type_color
fballiano 5b34f1d
Merge branch '1.9.4.x' into frontend_type_color
fballiano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* OpenMage | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/osl-3.0.php | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
* @copyright Copyright (c) 2023 The OpenMage Contributors (https://www.openmage.org) | ||
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
|
||
/** | ||
* Default config helper | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
class Mage_Adminhtml_Helper_Config extends Mage_Core_Helper_Abstract | ||
{ | ||
protected $_moduleName = 'Mage_Adminhtml'; | ||
|
||
/** | ||
* Return information array of input types | ||
* | ||
* @param string $inputType | ||
* @return array | ||
*/ | ||
public function getInputTypes(string $inputType = null): array | ||
{ | ||
$inputTypes = [ | ||
'color' => [ | ||
'backend_model' => 'adminhtml/system_config_backend_color' | ||
] | ||
]; | ||
|
||
if (is_null($inputType)) { | ||
return $inputTypes; | ||
} elseif (isset($inputTypes[$inputType])) { | ||
return $inputTypes[$inputType]; | ||
} | ||
return []; | ||
} | ||
|
||
/** | ||
* Return default backend model by input type | ||
* | ||
* @param string $inputType | ||
* @return string|null | ||
*/ | ||
public function getBackendModelByInputType(string $inputType): ?string | ||
{ | ||
$inputTypes = $this->getInputTypes(); | ||
if (!empty($inputTypes[$inputType]['backend_model'])) { | ||
return $inputTypes[$inputType]['backend_model']; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Get field backend model by field config node | ||
* | ||
* @param Varien_Simplexml_Element $fieldConfig | ||
* @return string|null | ||
*/ | ||
public function getBackendModelByFieldConfig(Varien_Simplexml_Element $fieldConfig): ?string | ||
{ | ||
if (isset($fieldConfig->backend_model)) { | ||
return (string)$fieldConfig->backend_model; | ||
} | ||
if (isset($fieldConfig->frontend_type)) { | ||
return $this->getBackendModelByInputType((string)$fieldConfig->frontend_type); | ||
} | ||
return null; | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Color.php
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,67 @@ | ||
<?php | ||
/** | ||
* OpenMage | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/osl-3.0.php | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
* @copyright Copyright (c) 2023 The OpenMage Contributors (https://www.openmage.org) | ||
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
|
||
/** | ||
* Color config field backend model | ||
* | ||
* @category Mage | ||
* @package Mage_Adminhtml | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
class Mage_Adminhtml_Model_System_Config_Backend_Color extends Mage_Core_Model_Config_Data | ||
{ | ||
/** | ||
* @throws Mage_Core_Exception | ||
* @return $this | ||
*/ | ||
protected function _beforeSave() | ||
{ | ||
/** @var Mage_Core_Model_Config_Element $config */ | ||
$config = $this->getFieldConfig(); | ||
|
||
$validate = []; | ||
if (isset($config->validate)) { | ||
$validate = array_map('trim', explode(' ', $config->validate)); | ||
} | ||
|
||
if (!(string)$this->getValue() && !in_array('required-entry', $validate)) { | ||
return $this; | ||
} | ||
|
||
$with_hash = true; | ||
if (isset($config->with_hash)) { | ||
$with_hash = $config->is('with_hash', true); | ||
} | ||
|
||
if ($with_hash) { | ||
$regex = Varien_Data_Form_Element_Color::VALIDATION_REGEX_WITH_HASH; | ||
$errorMessage = 'Color must be in hexadecimal format with the hash character'; | ||
} else { | ||
$regex = Varien_Data_Form_Element_Color::VALIDATION_REGEX_WITHOUT_HASH; | ||
$errorMessage = 'Color must be in hexadecimal format without the hash character'; | ||
} | ||
|
||
if (!(bool)preg_match($regex, (string)$this->getValue())) { | ||
Mage::throwException(Mage::helper('adminhtml')->__($errorMessage)); | ||
} | ||
|
||
return $this; | ||
} | ||
} |
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
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,79 @@ | ||
<?php | ||
/** | ||
* OpenMage | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/osl-3.0.php | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* @category Varien | ||
* @package Varien_Data | ||
* @copyright Copyright (c) 2023 The OpenMage Contributors (https://www.openmage.org) | ||
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
|
||
/** | ||
* Form text element | ||
* | ||
* @category Varien | ||
* @package Varien_Data | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
class Varien_Data_Form_Element_Color extends Varien_Data_Form_Element_Abstract | ||
{ | ||
public const VALIDATION_REGEX_WITH_HASH = '/^#[a-f0-9]{6}$/i'; | ||
public const VALIDATION_REGEX_WITHOUT_HASH = '/^[a-f0-9]{6}$/i'; | ||
|
||
/** | ||
* @param array $attributes | ||
*/ | ||
public function __construct($attributes = []) | ||
{ | ||
parent::__construct($attributes); | ||
$this->setType('text'); | ||
$this->setExtType('textfield'); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getHtmlAttributes() | ||
{ | ||
return ['type', 'title', 'class', 'style', 'oninput', 'disabled', 'readonly', 'tabindex']; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getElementHtml() | ||
{ | ||
$id = $this->getHtmlId(); | ||
$with_hash = strtolower((string) ($this->original_data['with_hash'] ?? 1)); | ||
|
||
if (!empty($with_hash) && $with_hash !== 'false' && $with_hash !== 'off') { | ||
$oninput = "document.getElementById('{$id}').value = this.value"; | ||
$regex = self::VALIDATION_REGEX_WITH_HASH; | ||
$this->setOninput("document.getElementById('{$id}:html5').value = {$regex}.test(this.value) ? this.value : '#000000'"); | ||
$this->addClass('validate-hex-color-hash'); | ||
} else { | ||
$oninput = "document.getElementById('{$id}').value = this.value.substring(1)"; | ||
$regex = self::VALIDATION_REGEX_WITHOUT_HASH; | ||
$this->setOninput("document.getElementById('{$id}:html5').value = {$regex}.test(this.value) ? '#'+this.value : '#000000'"); | ||
$this->addClass('validate-hex-color'); | ||
} | ||
|
||
$html = '<input type="color" id="' . $id . ':html5" class="input-color-html5" ' | ||
. 'value="#' . trim($this->getEscapedValue(), '#') . '" oninput="' . $oninput . '" ' | ||
. '/>' . "\n"; | ||
|
||
$this->addClass('input-color'); | ||
$html .= parent::getElementHtml(); | ||
return $html; | ||
} | ||
} |
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.
Is the author correct? Also, that email no longer work.
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.
we have the same on every file :-\ I don't remember if we did decide something about new files :-\
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.
@justinbeaty after writing command for updating docblocks ... ❤️
... is it possible to extend your script to replace headers for all added files since last release to change the "author"?
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.
We already had a discussion where someone wanted to add his company name ... cant find it atm.
I'd prefer to have something like OpenMage Developers ...
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 discussed in a proper discussion and/or rfc, I wouldn't block this PR which was supposed to be simple.
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.
also, we should ask adobe to speak about this, we shouldn't change the copyright but it doesn't make sense to keep these one...