Allow for default values of "0" (int) zero

Created on 2 January 2024, 12 months ago
Updated 26 July 2024, 5 months ago

Problem/Motivation

Schema Metatag uses empty() all over the place. This keeps things clean in many cases, but also removes all uses of "0" in the default values form.

This makes something as free shipping with Googles example impossible when using default values:

"shippingDetails": {
  "@type": "OfferShippingDetails",
  "shippingRate": {
    "@type": "MonetaryAmount",
    "value": "0",
    "currency": "USD"
},

Steps to reproduce

1. clean install and enable modules
2. enter "0" as a default value in a Schema Metatag field and save.
3. re-open and it's gone.

Proposed resolution

Change public static function arrayTrim($array) in SchemaMetatagManager.php from:

      if (empty($value)) {

to

      if (empty($value) && $value !=0 ) {

Remaining tasks

Does every $form['#default_value'] need to be checked for an empty value?;

$form['#default_value'] = !empty($value) ? $value : '';

User interface changes

none

API changes

none

Data model changes

none

🐛 Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

🇨🇳China splash112

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024