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

Created on 2 January 2024, 6 months ago
Updated 14 February 2024, 4 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

RTBC

Version

3.0

Component

Code

Created by

🇨🇳China splash112

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024