PHPackages                             dejvidecz/forms-doctrine - 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. [Database &amp; ORM](/categories/database)
4. /
5. dejvidecz/forms-doctrine

ActiveLibrary[Database &amp; ORM](/categories/database)

dejvidecz/forms-doctrine
========================

Helper for doctrine forms

1.3.4(4y ago)09PHPPHP &gt;=5.6

Since Jul 27Pushed 2y agoCompare

[ Source](https://github.com/dejvidecz/forms-doctrine)[ Packagist](https://packagist.org/packages/dejvidecz/forms-doctrine)[ RSS](/packages/dejvidecz-forms-doctrine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (9)Used By (0)

Fork of WebChemistry/forms-doctrine
===================================

[](#fork-of--webchemistryforms-doctrine)

[![Build Status](https://camo.githubusercontent.com/dcfcee969e8633ce84c826e343483b3cbdb6db0d91167d8a5ca2692e0adfcf52/68747470733a2f2f7472617669732d63692e6f72672f5765624368656d69737472792f666f726d732d646f637472696e652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/WebChemistry/forms-doctrine)

Installation
------------

[](#installation)

```
extensions:
    - WebChemistry\Forms\DoctrineExtension
```

Usage
-----

[](#usage)

Entity:

```
/**
 * @ORM\Entity()
 */
class User {

	/**
	 * @ORM\Id()
	 * @ORM\Column(type="integer", length=11)
	 * @ORM\GeneratedValue()
	 */
	private $id;

	/**
	 * @ORM\ManyToMany(targetEntity="Tests\Item", inversedBy="users")
	 */
	private $items;

	/**
	 * @ORM\ManyToOne(targetEntity="Tests\Role", inversedBy="users")
	 */
	private $role;

	/**
	 * @ORM\OneToOne(targetEntity="Tests\Notice", inversedBy="user")
	 */
	private $notice;

	public function __construct($id) {
		$this->items = new ArrayCollection();
		$this->setId($id);
	}

	public function addItem(Item $item) {
		$this->items->add($item);
		$item->addUser($this);
	}

	public function getItems() {
		return $this->items;
	}

	/**
	 * @return mixed
	 */
	public function getId() {
		return $this->id;
	}

	/**
	 * @param mixed $id
	 * @return self
	 */
	public function setId($id) {
		$this->id = $id;

		return $this;
	}

	/**
	 * @return Role
	 */
	public function getRole() {
		return $this->role;
	}

	public function setRole($role) {
		$this->role = $role;

		return $this;
	}

	/**
	 * @return mixed
	 */
	public function getNotice() {
		return $this->notice;
	}

	/**
	 * @param mixed $notice
	 * @return self
	 */
	public function setNotice($notice) {
		$this->notice = $notice;
		$notice->setUser($this);

		return $this;
	}

}
```

```
$values = [
	'id' => 5,
	'role' => [
		'id' => 1,
		'name' => 2
	],
	'items' => [
		['id' => 1] // Calls addItem() for each item
		['id' => 2]
	]
];
/** @var Entity\User $entity */
$entity = $this->helper->toEntity('Entity\User', $values);

$array = $this->helper->toArray($entity);

var_dump($array == $entity); // dumps true
```

Export selected items
---------------------

[](#export-selected-items)

```
public function export() {
    $settings = new new WebChemistry\Forms\Doctrine\Settings();
    $settings->setAllowedItems([
       'name', // Select name
       'items' => ['*'], // Select all items in items
       'role' => array('id') // Select id in role
    ]);

    $this->doctrine->toArray($this->entity, $settings);
}
```

Export one item in sub entities
-------------------------------

[](#export-one-item-in-sub-entities)

```
public function export() {
    $settings = new new WebChemistry\Forms\Doctrine\Settings();
    $settings->setJoinOneColumn(array(
        'role' => 'id'
    ));

    // Create array: ['role' => 5] instead of ['role' => ['id' => 5, 'name' => 'foo']]

    $this->doctrine->toArray($this->entity, $settings);
}
```

Custom callback
---------------

[](#custom-callback)

```
public function export() {
    $settings = new new WebChemistry\Forms\Doctrine\Settings();
    $settings->setCallbacks(array(
        'role' => function ($value, $entity) {
            return ['id' => $value->getId() * 2];
        }
    ));

    // Create array ['role' => ['id' => 10]] instead of ['role' => ['id' => 5, 'name' => 'foo']]

    $this->doctrine->toArray($this->entity, $settings);
}
```

Auto-find by ID
---------------

[](#auto-find-by-id)

```
public function export() {
    $settings = new new WebChemistry\Forms\Doctrine\Settings();
    $settings->setFind([
        'role' => 10 // Uses method find from repository
    ]);

    $this->doctrine->toArray($this->entity, $settings);
}
```

Usage in doctrine repository
----------------------------

[](#usage-in-doctrine-repository)

Change BaseRepository:

```
class BaseRepository {

    use WebChemistry\Forms\Doctrine\TBaseRepository;

}
```

and using:

```
class UserRepository {

    /**
     * @return Entity\User
     */
    public function toEntity(array $values, Entity\User $defaultEntity = NULL) {
        $settings = new WebChemistry\Forms\Doctrine\Settings();
        // ...

        return $this->convertToEntity($values, $defaultEntity, $settings);
    }

    /**
     * @return array
     */
    public function toArray(Entity\User $entity) {
        $settings = new new WebChemistry\Forms\Doctrine\Settings();
        // ...

        return $this->convertToArray($entity, $settings);
    }

    public function save(array $values) {
        $this->_em->persist($this->toEntity($values));
        $this->_em->flush();
    }

}
```

Usage in forms
--------------

[](#usage-in-forms)

```
/** @var WebChemistry\Forms\Doctrine @inject */
public $doctrine;

protected function createComponentForm() {
    $form = new WebChemistry\Forms\Form(); // For easier usage
    $form->setDoctrine($this->doctrine);

    $form->addText('name', 'User name')
         ->setRequired();

    $form->addText('password', 'Password')
         ->setRequired();

    $form->addCheckbox('remember', 'Remember');

    $form->addSubmit('submit', 'Sign in');

    $form->setEntity($this->em->getRepository('Entity\User')->find(1));

    return $form;
}

public function afterSign(WebChemistry\Forms\Application\Form $form) {
    $entity = $form->getEntity(); // Gets object from set object and fill it with new values
    $entity = $form->getEntity('Entity\User'); // Create new class
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~342 days

Recently: every ~517 days

Total

8

Last Release

1544d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4c7aa903b54827e55a6c6dffb510196db750c8f8658fd78254765c24f93b073?d=identicon)[dejvidecz](/maintainers/dejvidecz)

---

Top Contributors

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

---

Tags

helpernettedoctrineFormswebchemistry

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dejvidecz-forms-doctrine/health.svg)

```
[![Health](https://phpackages.com/badges/dejvidecz-forms-doctrine/health.svg)](https://phpackages.com/packages/dejvidecz-forms-doctrine)
```

###  Alternatives

[kdyby/doctrine

Doctrine integration into Nette Framework

1091.0M86](/packages/kdyby-doctrine)[nettrine/orm

Doctrine ORM for Nette Framework

581.9M37](/packages/nettrine-orm)[nettrine/migrations

Doctrine Migrations for Nette Framework

411.7M17](/packages/nettrine-migrations)[nettrine/dbal

Doctrine DBAL for Nette Framework

322.6M19](/packages/nettrine-dbal)[nettrine/annotations

Doctrine Annotations for Nette Framework

193.0M7](/packages/nettrine-annotations)[nettrine/fixtures

Doctrine Fixtures for Nette Framework

181.2M8](/packages/nettrine-fixtures)

PHPackages © 2026

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