Skip to content

DivanDesign/EvolutionCMS.snippets.ddObjectTools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

(MODX)EvolutionCMS.snippets.ddObjectTools

Tools for modifying objects.

Requires

Documentation

Installation

Elements → Snippets: Create a new snippet with the following data:

  1. Snippet name: ddObjectTools.
  2. Description: <b>0.2</b> Tools for modifying objects..
  3. Category: Core.
  4. Parse DocBlock: no.
  5. Snippet code (php): Insert content of the ddObjectTools_snippet.php file from the archive.

Parameters description

  • sourceObject

    • Desctription: Source object or array.
    • Valid values:
      • stringJsonObject — as JSON
      • stringJsonArray — as JSON
      • object
      • array
    • Default: '{}'
  • extend

    • Desctription: Merge the contents of two or more objects together into sourceObject (it will receive the new properties).
    • Valid values:
      • stringJsonObject — as JSON
      • object
      • arrayAssociative
    • Default value: —
  • extend->objects

    • Desctription: Objects or arrays to merge. Moreover, objects can extend arrays and vice versa.
    • Valid values: array
    • Required
  • extend->objects[i]

    • Desctription: An object or array containing additional properties to merge in.
    • Valid values:
      • object
      • array
    • Required
  • extend->deep

    • Desctription: If true, the merge becomes recursive (aka. deep copy).
    • Valid values: boolean
    • Default value: true
  • extend->overwriteWithEmpty

    • Desctription: Overwrite fields with empty values.
      The following values are considered to be empty:
      • '' — an empty string
      • [] — an empty array
      • (object) [] — an empty object
      • NULL
    • Valid values: boolean
    • Default value: true
  • getPropValue

    • Desctription: Object property name or array index to return.
    • Valid values: string
    • Default value: —

Examples

Merge the contents of two or more objects together into the first object (the extend parameter)

[[ddObjectTools?
	&sourceObject=`{
		"cat": "mew",
		"dog": {
			"name": "Floyd",
			"weight": 6
		},
		"rabbit": 42
	}`
	&extend=`{
		"objects": [
			{
				"dog": {
					"weight": 10
				},
				"bird": 0
			}
		]
	}`
]]

Returns:

{
	"cat": "mew",
	"dog": {
		"name": "Floyd",
		"weight": 10,
	},
	"rabbit": 42,
	"bird": 0,
}

Get an object property

[[ddObjectTools?
	&sourceObject=`{
		"firstName": "Chunk",
		"lastName": "Norris"
	}`
	&getPropValue=`firstName`
]]

Returns Chunk.

Get an array element

[[ddObjectTools?
	&sourceObject=`[
		"Pink Floyd",
		"The Beatles",
		"Queen"
	]`
	&getPropValue=`2`
]]

Returns Queen.

About

Tools for modifying objects.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages