<p>All you need to return from the <code>getStatuses()</code> method is an associative <code>array()</code> where the key represents the status <strong>name</strong> and the value represents the status <strong>label</strong>, more or less.</p>
<p>An example might be a set of statuses for a <strong>Payment</strong> element type:</p>
<pre class="lang-php prettyprint-override"><code>public function getStatuses()
{
    return array(
        'captured' =&gt; Craft::t('Captured'),
        'canceled' =&gt; Craft::t('Canceled'),
        'refunded' =&gt; Craft::t('Refunded'),
    );
}
</code></pre>
<p>Now, since it is likely that you'll be referring to and comparing against those statuses, it makes sense to give yourself a little extra insurance by creating a set of <a href="http://www.php.net/manual/en/language.oop5.constants.php" rel="noreferrer">class constants</a> instead of using plain strings.</p>
<p>That is exactly what Craft has done in the <strong>UserStatus</strong> class and you can achieve the same result in one of two ways.</p>
<hr />
<p><strong>1.</strong> Create your own class and define those constants</p>
<pre class="lang-php prettyprint-override"><code>// plugin/enums/PluginPaymentStatus.php
namespace Craft;

class PluginPaymentStatus
{
    const CAPTURED = 'captured';
    const CANCELED = 'canceled';
    const REFUNDED = 'refunded';
}

// plugin/elementtypes/PluginElementType.php
public function getStatuses()
{
    return array(
        PluginPaymentStatus::CAPTURED =&gt; Craft::t('Captured'),
        PluginPaymentStatus::CANCELED =&gt; Craft::t('Canceled'),
        PluginPaymentStatus::REFUNDED =&gt; Craft::t('Refunded'),
    );
}
</code></pre>
<p><strong>2.</strong> Create the status constants in your element type model if you have one</p>
<hr />
<p>Note that if you go with option <strong>1</strong>, you will need to <strong>import|include|require</strong> your <strong>&quot;enum&quot;</strong>.</p>

CC BY-SA 3.0
2014-07-10T09:42:08.547Z
2014-07-10T09:42:08.547Z
2020-06-17T08:56:27.903Z
Selvin Ortiz
<p>I'm working on a plugin with its own element type, I'm trying to add custom statuses to the element type. What is the best way to proceed? I have hasStatuses set to true and getStatuses is where I would set them.. But what should the array look like thats returned?</p>

<p>UserElementType returns this:</p>

<pre><code>/**
 * Returns all of the possible statuses that elements of this type may have.
 *
 * @return array|null
 */
public function getStatuses()
{
    return array(
        UserStatus::Active    =&gt; Craft::t('Active'),
        UserStatus::Pending   =&gt; Craft::t('Pending'),
        UserStatus::Locked    =&gt; Craft::t('Locked'),
        UserStatus::Suspended =&gt; Craft::t('Suspended'),
        UserStatus::Archived  =&gt; Craft::t('Archived')
    );
} 
</code></pre>

CC BY-SA 3.0
2014-07-10T08:05:52.650Z
So I did a little bit more research and noticed that the UserStatus is an enum. Is this a possibility to implement in a Craft plugin?
Jason McCallister
<plugin-development><elementtype>
Best way to implement my own statuses on my custom element type?
# Best way to implement my own statuses on my custom element type?

(Asked by: username_0 on 2014-07-10)

I'm working on a plugin with its own element type, I'm trying to add custom statuses to the element type. What is the best way to proceed? I have hasStatuses set to true and getStatuses is where I would set them.. But what should the array look like thats returned?
UserElementType returns this:
/**
 * Returns all of the possible statuses that elements of this type may have.
 *
 * @return array|null
 */
public function getStatuses()
{
    return array(
        UserStatus::Active    => Craft::t('Active'),
        UserStatus::Pending   => Craft::t('Pending'),
        UserStatus::Locked    => Craft::t('Locked'),
        UserStatus::Suspended => Craft::t('Suspended'),
        UserStatus::Archived  => Craft::t('Archived')
    );
}

**Tags:** plugin-development, elementtype
> **Comments:**
> **username_0**: So I did a little bit more research and noticed that the UserStatus is an enum. Is this a possibility to implement in a Craft plugin?  

---

## 1 answers

### Answer by username_1 on 2014-07-10. Score: 12 | Accepted answer

All you need to return from the getStatuses() method is an associative array() where the key represents the status name and the value represents the status label, more or less.
An example might be a set of statuses for a Payment element type:
public function getStatuses()
{
    return array(
        'captured' => Craft::t('Captured'),
        'canceled' => Craft::t('Canceled'),
        'refunded' => Craft::t('Refunded'),
    );
}

Now, since it is likely that you'll be referring to and comparing against those statuses, it makes sense to give yourself a little extra insurance by creating a set of class constants instead of using plain strings.
That is exactly what Craft has done in the UserStatus class and you can achieve the same result in one of two ways.

1. Create your own class and define those constants
// plugin/enums/PluginPaymentStatus.php
namespace Craft;

class PluginPaymentStatus
{
    const CAPTURED = 'captured';
    const CANCELED = 'canceled';
    const REFUNDED = 'refunded';
}

// plugin/elementtypes/PluginElementType.php
public function getStatuses()
{
    return array(
        PluginPaymentStatus::CAPTURED => Craft::t('Captured'),
        PluginPaymentStatus::CANCELED => Craft::t('Canceled'),
        PluginPaymentStatus::REFUNDED => Craft::t('Refunded'),
    );
}

2. Create the status constants in your element type model if you have one

Note that if you go with option 1, you will need to import|include|require your "enum".


---

