This module allows the admin account (user 1) to add fields, filters and sorts to views which use PHP code. It also supports additional accounts when the core PHP Filter module is enabled.

This is the successor of Views Custom Field for both D6 and D7. The D6 version supports both Views 2 and Views 3.

Note

While this module allows you to directly use PHP inside views which may be useful for quick and easy solutions, it is highly advisable to use regular handlers and plugins when available (or even to create one yourself). Take note that filtering and sorting a view using PHP always has a considerable performance impact.

Alternatives

An alternative to this module is Computed field. It lets you add an actual field to your entities where you specify the PHP code you'd like to run. You can store the computed result in the database or have it run on the fly when viewed directly or through Views. It also lets you implement hooks in your own modules which hold your computation code so it can be version controlled. Views PHP doesn't have this ability, but there's a feature request for this over at #1326780: Provide function templates for code to use instead of text areas.

To alter SQL queries you could use modules like Views Raw SQL and Views Custom Conditions.

Available handlers

Area
An (header/footer/empty) area which output is constructed by the administrator using PHP.
Field
A field which value and/or output is constructed by the administrator using PHP. Click-sort is also available and accepts a number of predefined sort algorithms or custom PHP.
Filter
A filter based on custom PHP code; use PHP to filter out any row.
Sort
A sort based on custom PHP code; use PHP to sort the result of a view.

Available plugins

Access
Access control based on custom PHP code; use PHP to determine whether a user has access to a view.
Cache
Cache control based on custom PHP code; use PHP to determine whether a view's (result/output) cache is still fresh.

Versions

7.x-1.x
Receives only critical bug fixes.
7.x-2.x
Unsupported: Users of this version are advised to switch to 7.x-1.x. There are few differences between them and no update hooks, so you can probably just switch versions. Feature development may happen here if a maintainer steps forward. This may include bug fixes and may not be backwards compatible with 7.x-1.x.
8.x-1.x
Unsupported. Do not use this in Drupal 8 or later. Use Views plugins / field formatters.

Project information

  • caution Minimally maintained
    Maintainers monitor issues, but fast responses are not guaranteed.
  • caution Maintenance fixes only
    Considered feature-complete by its maintainers.
  • chart icon37,294 sites report using this module
  • Created by casey on , updated
  • Arrow iconDrupal 10 is here!

    Do not use this in Drupal 8 or later. Use Views plugins.

  • shieldStable releases for this project are covered by the security advisory policy.
    Look for the shield icon below.

Releases