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

validateNameIsNotReserved validation rule unnecessarily requires add-on to have been called from CP #4339

Open
jcogs-design opened this issue May 31, 2024 · 0 comments

Comments

@jcogs-design
Copy link
Contributor

jcogs-design commented May 31, 2024

Description of the problem
The process of creating a new field from an add-on is documented, including an example code snippet.
When applying this code-snippet from an add-on that is not called from within CP, the field validation step triggers an EE exception error, this effectively prevents add-ons not called from within CP from validating the field before it is saved.

The validation exception is caused by a call to ee()->cp->invalid_custom_field_names() (which exists within the CP model) which simply returns an array of protected strings; there is no apparent reason why this simple method needs to be tied to the CP model (the code comprises 100% regular php).

How To Reproduce
Implement the example code in an addon called from outside the CP.

Error Messages


InvalidArgumentException Caught
No such property: 'cp' on ExpressionEngine\Legacy\Facade

ee/ExpressionEngine/Legacy/Facade.php:128
Stack Trace: Please include when reporting this error

    #0 ee/ExpressionEngine/Legacy/Facade.php(35): ExpressionEngine\Legacy\Facade->get()
    #1 ee/ExpressionEngine/Model/Content/FieldModel.php(567): ExpressionEngine\Legacy\Facade->__get()
    #2 ee/ExpressionEngine/Service/Validation/Validator.php(246): ExpressionEngine\Model\Content\FieldModel->validateNameIsNotReserved()
    #3 [internal function]: ExpressionEngine\Service\Validation\Validator->ExpressionEngine\Service\Validation\{closure}()
    #4 ee/ExpressionEngine/Service/Validation/Rule/Callback.php(30): call_user_func()
    #5 ee/ExpressionEngine/Service/Validation/Validator.php(188): ExpressionEngine\Service\Validation\Rule\Callback->validate()
    #6 ee/ExpressionEngine/Service/Validation/Validator.php(127): ExpressionEngine\Service\Validation\Validator->_validate()
    #7 ee/ExpressionEngine/Service/Model/Model.php(482): ExpressionEngine\Service\Validation\Validator->validate()
    #8 ee/ExpressionEngine/Model/Content/FieldModel.php(107): ExpressionEngine\Service\Model\Model->validate()
    #9 user/addons/jcogs_heffiq/Service/HeffiqUtilities.php(62): ExpressionEngine\Model\Content\FieldModel->validate()
    #10 user/addons/jcogs_heffiq/Tags/Products.php(66): JCOGSDesign\JCOGSHeffiq\Service\HeffiqUtilities->create_ee_field()
    #11 ee/ExpressionEngine/Service/Addon/Module.php(68): JCOGSDesign\JCOGSHeffiq\Tags\Products->process()
    #12 ee/ExpressionEngine/Service/Addon/Module.php(51): ExpressionEngine\Service\Addon\Module->route()
    #13 ee/ExpressionEngine/Service/Addon/Module.php(118): ExpressionEngine\Service\Addon\Module->routeTag()
    #14 ee/legacy/libraries/Template.php(1835): ExpressionEngine\Service\Addon\Module->__call()
    #15 ee/legacy/libraries/Template.php(1510): EE_Template->process_tags()
    #16 ee/legacy/libraries/Template.php(625): EE_Template->tags()
    #17 ee/legacy/libraries/Template.php(248): EE_Template->parse()
    #18 ee/legacy/libraries/Template.php(178): EE_Template->fetch_and_parse()
    #19 ee/legacy/libraries/Core.php(811): EE_Template->run_template_engine()
    #20 ee/legacy/controllers/ee.php(53): EE_Core->generate_page()
    #21 [internal function]: EE->index()
    #22 ee/ExpressionEngine/Core/Core.php(268): call_user_func_array()
    #23 ee/ExpressionEngine/Core/Core.php(124): ExpressionEngine\Core\Core->runController()
    #24 ee/ExpressionEngine/Boot/boot.php(184): ExpressionEngine\Core\Core->run()
    #25 public_html/index.php(173): require_once('...')
    #25 public_html/index.php(173): require_once('...') 

Environment Details:

  • Version: 7.4.9
  • PHP Version 8.3

Possible Solution
Relocate the invalid_custom_field_names method to somewhere that accessible all the time... ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant