PHPackages                             dartanian300/xmodule-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. dartanian300/xmodule-php

ActiveLibrary

dartanian300/xmodule-php
========================

A PHP implementation of Modo Lab's Xmodule specification

v1.2.0(6y ago)110MITPHPPHP &gt;=7.0.0CI failing

Since Sep 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/dartanian300/Xmodule-PHP)[ Packagist](https://packagist.org/packages/dartanian300/xmodule-php)[ RSS](/packages/dartanian300-xmodule-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Xmodule-PHP
===========

[](#xmodule-php)

A PHP library for implementing Modo Lab's XModule web service.

This library follows the XModule v1.0 specification as much as possible. Unless otherwise stated, each element can be instantiated via a camel-case version of their name (from the specification). For easiest use, reference the specification while using this library (while keeping in mind the "Things to remember" below).

To Install:

```
$ composer require dartanian300/xmodule-php
```

Be sure to include Composer's autoloader

```
require(__DIR__.'/vendor/autoload.php');
```

Use the elements together to create your XModule response:

```
// Create root response element
$response = new XModuleResponse();

// Create content elements
$container = new ButtonContainer();
$button = new LinkButton();

$button->title->set("Click Me");
$container->add($button);

// Add elements to root response element
$response->add($container);

// Print JSON response
echo json_encode($response);
```

Few things to remember:

- All elements will check for required fields when `json_encode()` is called. If there's a missing field, an exception will be thrown.
- String fields with predefined values are set using the value as a function (ex - setting `actionType` to 'constructive': `$linkBbutton->actionType->constructive()`)
- Freeform string fields accessed via `set()` &amp; `get()`
- Boolean fields accessed via `get()`, `true()` &amp; `false()`
- Array fields are generally accessed via `add()`, `get()`, `delete()` (if multiple arrays, append camel-case attribute name. See "Using elements with multiple array fields" example below)
- `elementType` &amp; `inputType` fields are automatically set

Get Started Examples
====================

[](#get-started-examples)

#### Access/Set predefined string fields

[](#accessset-predefined-string-fields)

```
$collapsible = new Collapsible();
$collapsible->disclosureIcon->plusminus();
$collapsible->disclosureIcon->get();
```

#### Access/Set freeform string fields

[](#accessset-freeform-string-fields)

```
$collapsible = new Collapsible();
$collapsible->title->set("I'm a collapsible title!");
$collapsible->title->get();
```

#### Access/Set boolean fields

[](#accessset-boolean-fields)

```
$collapsible = new Collapsible();
$collapsible->collapsed->true();
$collapsible->collapsed->get();
```

#### Access/Set/Delete array fields

[](#accesssetdelete-array-fields)

```
$collapsible = new Collapsible();

$img = new Image();
$img->url->set('http://...');

$collapsible->add($img);
$collapsible->get(0);
$collapsible->delete(0);
```

#### Access/Set/Delete object fields

[](#accesssetdelete-object-fields)

```
$container = new Container();
$container->margins->responsive();

$detail = new Detail();
$detail->thumbnail->url->set('http://...');
$detail->thumbnail->crop->true();
```

#### Access/Set id field

[](#accessset-id-field)

```
$collapsible = new Collapsible('collapse1');

// OR

$collapsible = new Collapsible();
$collapsible->setId('collapse1');
```

> **Note:** ids can only be set on elements that support it

#### Access elementType field

[](#access-elementtype-field)

```
$collapsible = new Collapsible();
$collapsible->getElementType();
```

More Examples
=============

[](#more-examples)

#### Using elements with multiple array fields

[](#using-elements-with-multiple-array-fields)

```
$table = new Table();

$row = new \XModule\Helpers\Row();
$table->addRow($row);
$table->getRow(0);
$table->deleteRow(0);

$columnOption = new \XModule\Helpers\ColumnOption();
$table->addColumnOption($columnOption);
$table->getColumnOption(0);
$table->deleteColumnOption(0);
```

#### Using forms

[](#using-forms)

```
// Create root response element
$response = new XModuleResponse();

// Create root form element
$form = new Form();
$form->relativePath->set('./');

// Create inputs
$nameInput = new TextInput();
$nameInput->name->set("first-name");
$nameInput->label->set("First Name");

$selectState = new SelectMenu();
$selectState->name->set("state");
$selectState->label->set("State");
$optionLabels = ['New York', 'Georgia', 'California'];
$optionValues = ['NY', 'GA', 'CA'];
$selectState->addOptionLabel($optionLabels);
$selectState->addOptionValue($optionValues);

// OR store in associative array

//$optionValues = [
//    //label - value
//    'New York'  => 'NY',
//    'Georgia'   => 'GA',
//    'California'    =>  'CA'
//];
//foreach($optionValues as $label => $value){
//    $selectState->addOptionLabel($label);
//    $selectState->addOptionValue($value);
//}

$comments = new TextArea();
$comments->name->set('comments');
$comments->label->set('Comments');

// Add fields to form
$form->add([$nameInput, $selectState, $comments]);

// Add form to root response element
$response->add($form);

// Print JSON response
echo json_encode($response);
```

#### Using MultiColumn

[](#using-multicolumn)

```
// Create root response element
$response = new XModuleResponse();

// Create multicolumn element
$columns = new MultiColumn(2);

// Create content
$text = new Detail();
$text->title->set('Welcome');
$text->body->set('See to the right');
$image = new Image();
$image->url->set('https://image.shutterstock.com/image-photo/large-beautiful-drops-transparent-rain-260nw-668593321.jpg');

// Add content to multicolumn
$columns->add(0, $text);
$columns->add(1, $image);

// Add multicolumn to root response element
$response->add($columns);

// Print JSON response
echo json_encode($response);
```

A few exceptions
----------------

[](#a-few-exceptions)

Some fields/elements use a modified `add()` method. See their signatures below:

- `ProgressiveDisclosureItems` and `QueryParameters` fields: `add($key, $element)`.
- `MultiColumn` elements: `add($columnNum, $element)`.

More Documentation
==================

[](#more-documentation)

More documentation can be found by navigating to the `docs` folder in a browser after running the following command:

```
$ composer make-docs
```

> **Note:** Assumes that PHPDoc is installed in the project's 'vendor' folder and that you are executing on a Unix-based system. Command might need to be modified to work on Windows systems (located in `composer.json`).

Element Reference
=================

[](#element-reference)

Available Top-Level Elements:
-----------------------------

[](#available-top-level-elements)

- **Root Element:** XModuleResponse
- AutoUpdateAccessibility
- ButtonContainer
- Carousel
- Collapsible
- Container
- Detail
- GoogleMap
- Grid
- Heading
- HTML
- Image
- Link
- LinkButton
- LoadingIndicator
- MultiColumn
- Portlet
- Table
- Tabs
- Toolbar
- ToolbarContent
- XList (renamed from specification's List since that's a reserved word in PHP)

Available Form Elements:
------------------------

[](#available-form-elements)

- **Root Element:** Form
- Checkbox
- Email
- FormButton
- HiddenField
- Label
- Password
- Phone
- RadioButtons
- SelectMenu
- TextArea
- TextInput
- Upload

Available GoogleMaps Elements (namespace: XModule\\GoogleMaps):
---------------------------------------------------------------

[](#available-googlemaps-elements-namespace-xmodulegooglemaps)

- MapPoint
- MapPolygon
- MapPolyline
- Point

(namespace: XModule\\GoogleMaps\\MapPoint)

- Anchor
- Icon
- Size

Available Toolbar Elements (namespace: XModule\\Toolbar):
---------------------------------------------------------

[](#available-toolbar-elements-namespace-xmoduletoolbar)

- MenuItem
- ToolbarButton
- ToolbarLabel
- ToolbarMenu

Available Helper Elements (namespace: XModule\\Helpers)
-------------------------------------------------------

[](#available-helper-elements-namespace-xmodulehelpers)

### For use with `Table`

[](#for-use-with-table)

- ColumnOption
- Row
- Cell

### For use with `Carousel`

[](#for-use-with-carousel)

- CarouselItem

### For use with `Grid`

[](#for-use-with-grid)

- GridItem

### For use with `XList`

[](#for-use-with-xlist)

- ListItem

### For use with `Tabs`

[](#for-use-with-tabs)

- Tab

Concepts Not Currently Implemented
==================================

[](#concepts-not-currently-implemented)

- DynamicPlacemarks field (in `GoogleMap`)
- XComponents

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Total

3

Last Release

2431d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/624d150a9606857f15696b6674d21adcda260bdd6cb27a549a76edec09395306?d=identicon)[dartanian300](/maintainers/dartanian300)

---

Top Contributors

[![dartanian300](https://avatars.githubusercontent.com/u/3358537?v=4)](https://github.com/dartanian300 "dartanian300 (137 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dartanian300-xmodule-php/health.svg)

```
[![Health](https://phpackages.com/badges/dartanian300-xmodule-php/health.svg)](https://phpackages.com/packages/dartanian300-xmodule-php)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
