@@ 23-66 (lines=44) @@ | ||
20 | * @param Datetime $type |
|
21 | * @return callable |
|
22 | */ |
|
23 | public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
24 | { |
|
25 | /** |
|
26 | * Creates an entity. |
|
27 | * |
|
28 | * @param array $input The input for the mutation |
|
29 | * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | * @return array |
|
32 | */ |
|
33 | return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
34 | try { |
|
35 | EntityMutator::checkPermissions($model); |
|
36 | ||
37 | $tickets = []; |
|
38 | $args = DatetimeMutation::prepareFields($input); |
|
39 | ||
40 | if (isset($args['tickets'])) { |
|
41 | $tickets = $args['tickets']; |
|
42 | unset($args['tickets']); |
|
43 | } |
|
44 | ||
45 | $entity = EE_Datetime::new_instance($args); |
|
46 | $id = $entity->save(); |
|
47 | EntityMutator::validateResults($id); |
|
48 | ||
49 | if (! empty($tickets)) { |
|
50 | DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
51 | } |
|
52 | } catch (Exception $exception) { |
|
53 | EntityMutator::handleExceptions( |
|
54 | $exception, |
|
55 | esc_html__( |
|
56 | 'The datetime could not be created because of the following error(s)', |
|
57 | 'event_espresso' |
|
58 | ) |
|
59 | ); |
|
60 | } |
|
61 | ||
62 | return [ |
|
63 | 'id' => $id, |
|
64 | ]; |
|
65 | }; |
|
66 | } |
|
67 | } |
|
68 |
@@ 23-66 (lines=44) @@ | ||
20 | * @param Datetime $type |
|
21 | * @return callable |
|
22 | */ |
|
23 | public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
24 | { |
|
25 | /** |
|
26 | * Updates an entity. |
|
27 | * |
|
28 | * @param array $input The input for the mutation |
|
29 | * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | * @return array |
|
32 | */ |
|
33 | return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
34 | try { |
|
35 | /** @var EE_Datetime $entity */ |
|
36 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
37 | ||
38 | $tickets = []; |
|
39 | $args = DatetimeMutation::prepareFields($input); |
|
40 | ||
41 | if (isset($args['tickets'])) { |
|
42 | $tickets = $args['tickets']; |
|
43 | unset($args['tickets']); |
|
44 | } |
|
45 | ||
46 | // Update the entity |
|
47 | $entity->save($args); |
|
48 | ||
49 | if (! empty($tickets)) { |
|
50 | DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
51 | } |
|
52 | } catch (Exception $exception) { |
|
53 | EntityMutator::handleExceptions( |
|
54 | $exception, |
|
55 | esc_html__( |
|
56 | 'The datetime could not be updated because of the following error(s)', |
|
57 | 'event_espresso' |
|
58 | ) |
|
59 | ); |
|
60 | } |
|
61 | ||
62 | return [ |
|
63 | 'id' => $entity->ID(), |
|
64 | ]; |
|
65 | }; |
|
66 | } |
|
67 | } |
|
68 |