public static function JobItem::getStateDefinitions

7 calls to JobItem::getStateDefinitions()
JobItem::getStateIcon in src/Entity/JobItem.php
Returns a render array to display a job item state icon.
JobItemState::getValueOptions in src/Plugin/views/filter/JobItemState.php
Gets the values of the options.
JobState::getValueOptions in src/Plugin/views/filter/JobState.php
Gets the values of the options.
JobState::query in src/Plugin/views/filter/JobState.php
tmgmt_color_job_item_legend in ./tmgmt.module
Provides color legends for job item states.

... See full list

File

src/Entity/JobItem.php, line 1170

Class

JobItem
Entity class for the tmgmt_job_item entity.

Namespace

Drupal\tmgmt\Entity

Code

public static function getStateDefinitions() {
  if (!empty(static::$stateDefinitions)) {
    return static::$stateDefinitions;
  }
  static::$stateDefinitions = [
    static::STATE_ACTIVE => [
      'label' => t('In progress'),
      'type' => 'state',
      'icon' => \Drupal::service('extension.list.module')
        ->getPath('tmgmt') . '/icons/hourglass.svg',
      'weight' => 0,
      'show_job_filter' => TRUE,
    ],
    static::STATE_REVIEW => [
      'label' => t('Needs review'),
      'type' => 'state',
      'icon' => \Drupal::service('extension.list.module')
        ->getPath('tmgmt') . '/icons/ready.svg',
      'weight' => 5,
      'show_job_filter' => TRUE,
    ],
    static::STATE_ACCEPTED => [
      'label' => t('Accepted'),
      'type' => 'state',
      'weight' => 10,
    ],
    static::STATE_ABORTED => [
      'label' => t('Aborted'),
      'type' => 'state',
      'weight' => 15,
    ],
    static::STATE_INACTIVE => [
      'label' => t('Inactive'),
      'type' => 'state',
      'icon' => \Drupal::service('extension.list.module')
        ->getPath('tmgmt') . '/icons/rejected.svg',
      'weight' => 20,
    ],
  ];
  \Drupal::moduleHandler()
    ->alter('tmgmt_job_item_state_definitions', static::$stateDefinitions);
  foreach (static::$stateDefinitions as $key => &$definition) {

    // Ensure that all state definitions have a type and label key set.
    assert(!empty($definition['type']) && !empty($definition['label']), "State definition {$key} is missing label or type.");

    // Set the default weight to 25, after the default states.
    $definition += [
      'weight' => 25,
    ];
  }
  uasort(static::$stateDefinitions, [
    SortArray::class,
    'sortByWeightElement',
  ]);
  return static::$stateDefinitions;
}