From bdef1d02ae49c5e54be29c5eecde631effed5604 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sun, 28 Apr 2024 17:59:23 +0300 Subject: [PATCH] minor improvements --- app/config/.env.example | 2 ++ app/config/app.php | 11 +++++++++++ app/src/View/Helper/FieldHelper.php | 4 +++- app/templates/element/form/nameDiv.php | 23 ++++++++++++++++------- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/app/config/.env.example b/app/config/.env.example index 15060f7be..f5ac424ce 100644 --- a/app/config/.env.example +++ b/app/config/.env.example @@ -25,6 +25,8 @@ export SECURITY_SALT="__SALT__" #export CACHE_DEFAULT_URL="file://tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}" #export CACHE_CAKECORE_URL="file://tmp/cache/persistent?prefix=${APP_NAME}_cake_core&serialize=true&duration=${CACHE_DURATION}" #export CACHE_CAKEMODEL_URL="file://tmp/cache/models?prefix=${APP_NAME}_cake_model&serialize=true&duration=${CACHE_DURATION}" +#export CACHE_CAKEROUTE_URL="file://tmp/cache/routes?prefix=${APP_NAME}_cake_routes&serialize=true&duration=${CACHE_DURATION}" +#export CACHE_HTMLELEMENT_URL="file://tmp/cache/elements?prefix=${APP_NAME}_html_elements&serialize=true&duration=${CACHE_DURATION}" # Uncomment these to define email transport configuration via environment variables. #export EMAIL_TRANSPORT_DEFAULT_URL="" diff --git a/app/config/app.php b/app/config/app.php index 0acaef633..3644eaa34 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -171,6 +171,17 @@ 'duration' => '+1 years', 'url' => env('CACHE_CAKEROUTES_URL', null), ], + /** + * Configure the cache for html elements. + * Duration will be set to '+2 seconds' in bootstrap.php when debug = true + */ + '_html_elements' => [ + 'className' => 'Cake\Cache\Engine\FileEngine', + 'prefix' => 'myapp_cake_elements_', + 'duration' => '+1 week', + 'probability' => 100, + 'url' => env('CACHE_HTMLELEMENT_URL', null), + ] ], /** diff --git a/app/src/View/Helper/FieldHelper.php b/app/src/View/Helper/FieldHelper.php index d74b45af1..205dd2f64 100644 --- a/app/src/View/Helper/FieldHelper.php +++ b/app/src/View/Helper/FieldHelper.php @@ -213,7 +213,9 @@ public function dateField(string $fieldName, // ACTION VIEW if($this->action == 'view') { // return the date as plaintext - $element = $this->getView()->element('form/notSetDiv'); + $element = $this->getView()->element('form/notSetDiv', [], [ + 'cache' => '_html_elements', + ]); if ($date_object !== null) { // Adjust the time back to the user's timezone $element = ''; diff --git a/app/templates/element/form/nameDiv.php b/app/templates/element/form/nameDiv.php index fa76b0c17..06ab77505 100644 --- a/app/templates/element/form/nameDiv.php +++ b/app/templates/element/form/nameDiv.php @@ -37,7 +37,6 @@ use Cake\Utility\Inflector; -// $fieldName: parameter $classes = ''; @@ -59,7 +58,7 @@ [$label, $desc] = $this->Field->calculateLabelAndDescription($fn); $label = $vv_field_arguments['fieldLabel'] ?? $label; -// Override the default required behavior is the field has the required +// Override the default required behavior if the field has the required // option set $optionsRequired = isset($vv_field_arguments['fieldOptions']['required']) && $vv_field_arguments['fieldOptions']['required']; @@ -73,8 +72,11 @@
- Field->getFieldType($fieldName) !== 'boolean'): ?> + Field->getFieldType($fieldName) !== 'boolean' + ): + ?> Form->label($fn, $label) ?> @@ -82,16 +84,23 @@ Field->isEditable() && ($this->Field->isReqField($fn) || $optionsRequired) ) { - print $this->element('form/requiredSpan'); + print $this->element('form/requiredSpan', [], [ + 'cache' => '_html_elements', + ]); } ?>
-
+
+ +
\ No newline at end of file