Download the PHP package drupal-utils/entity-convert without Composer

On this page you can find all versions of the php package drupal-utils/entity-convert. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package entity-convert

EntityConvert

Test Cases

Latest Stable Version Total Downloads Latest Unstable Version License

PHP Library built to be used with Drupal codebase/modules only. Parses and simplifies the passed Node/Taxonomy/User/File (drupal entities) fully loaded object into a Simple array of fields or an Object which can be used directly to build any view or REST response layer.

Usually we implement helper classes/methods to resolve the field values for a given entity instance, the idea behind this is always to reduce duplicate code and to provide a uniform interface to access the field values.

Every Drupal Entity instance also has a method associated with it, which returns all the field values as an array, which is also a good way to access all the values but the only limitation i found with using the toArray() method is all the values are returned as string hence loosing it original type and the way they are rendered. This library tries to return value as a single level and also accepts a parameter while parsing the Entity object so to maintain its original data types (useful when building REST API's).

I decided to write this library to reduce the need to write additional helper classes/methods every time we introduce a new Entity type.


Install

Get from Packagist using Composer

  1. From the root of your Drupal project run. Link to Packagist

Usage

Consider Entity type "Node" having associated the below default field types to it

Drupal way

How field value is accessed normally in the code.

Accessing the value of fields associated with a Node entity

Boolean Field

DateTime Field

Date Field

Email Field

File Field

List Text Field

Using the library

Get response as array of field => values

Get response as an object

If the response is an object, all available fields/values can be accessed as a property.

API

The methods toArray/toObject (instance, strict_type) accepts 2 arguments.

- instance = Loaded instance object of the type Node/User/Taxonomy/File.
- strict_type = Boolean: Returned response has all data types preserved.

When we get value from field attached to an Entity, drupal will usually return all values as string. Sending second parameter as true, the library will typecast all the value to correct data type.

Reference

Method Parameters Comment
toArray Object of type Node/User/Taxonomy or File
  = false Boolean flag representing whether value to be type casted
toObject Object of type Node/User/Taxonomy or File
  = false Boolean flag representing whether value to be type casted

All versions of entity-convert with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package drupal-utils/entity-convert contains the following files

Loading the files please wait ....