FieldDomainIdSpecProvider.php 1.23 KB
Newer Older
1 2
<?php

totten's avatar
totten committed
3 4
/*
 +--------------------------------------------------------------------+
5
 | Copyright CiviCRM LLC. All rights reserved.                        |
totten's avatar
totten committed
6
 |                                                                    |
7 8 9
 | This work is published under the GNU AGPLv3 license with some      |
 | permitted exceptions and without any warranty. For full license    |
 | and copyright information, see https://civicrm.org/licensing       |
totten's avatar
totten committed
10 11 12 13 14 15
 +--------------------------------------------------------------------+
 */

/**
 *
 * @package CRM
16
 * @copyright CiviCRM LLC https://civicrm.org/licensing
totten's avatar
totten committed
17 18 19 20 21
 * $Id$
 *
 */


22 23 24 25
namespace Civi\Api4\Service\Spec\Provider;

use Civi\Api4\Service\Spec\RequestSpec;

26
class FieldDomainIdSpecProvider implements Generic\SpecProviderInterface {
27 28

  /**
29
   * Generic create spec function to set sensible defaults for any entity with a "domain_id" field.
30 31
   */
  public function modifySpec(RequestSpec $spec) {
32
    $domainIdField = $spec->getFieldByName('domain_id');
33
    if ($domainIdField && $domainIdField->isRequired()) {
34 35
      $domainIdField->setRequired(FALSE)->setDefaultValue('current_domain');;
    }
36 37 38 39 40 41
  }

  /**
   * @inheritDoc
   */
  public function applies($entity, $action) {
42
    return $action === 'create';
43 44 45
  }

}