| @@ 19-70 (lines=52) @@ | ||
| 16 | use WPGraphQL\AppContext; |
|
| 17 | use GraphQL\Error\UserError; |
|
| 18 | ||
| 19 | class DatetimeCreate |
|
| 20 | { |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Defines the mutation data modification closure. |
|
| 24 | * |
|
| 25 | * @param EEM_Datetime $model |
|
| 26 | * @param Datetime $type |
|
| 27 | * @return callable |
|
| 28 | */ |
|
| 29 | public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
| 30 | { |
|
| 31 | /** |
|
| 32 | * Creates an entity. |
|
| 33 | * |
|
| 34 | * @param array $input The input for the mutation |
|
| 35 | * @param AppContext $context The AppContext passed down to all resolvers |
|
| 36 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
| 37 | * |
|
| 38 | * @throws UserError |
|
| 39 | * @throws ReflectionException |
|
| 40 | * @throws InvalidArgumentException |
|
| 41 | * @throws InvalidInterfaceException |
|
| 42 | * @throws InvalidDataTypeException |
|
| 43 | * @throws EE_Error |
|
| 44 | */ |
|
| 45 | return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) |
|
| 46 | { |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Stop now if a user isn't allowed to create a datetime. |
|
| 50 | */ |
|
| 51 | if (! current_user_can('ee_edit_events')) { |
|
| 52 | // translators: the %1$s is the name of the object being mutated |
|
| 53 | throw new UserError(sprintf(__('Sorry, you are not allowed to create %1$s', 'event_espresso' ), $type->name())); |
|
| 54 | } |
|
| 55 | ||
| 56 | $args = DatetimeMutation::prepare_fields($input); |
|
| 57 | ||
| 58 | $entity = EE_Datetime::new_instance($args); |
|
| 59 | $id = $entity->save(); |
|
| 60 | ||
| 61 | if (empty($id)) { |
|
| 62 | throw new UserError(__( 'The object failed to create but no error was provided', 'event_espresso')); |
|
| 63 | } |
|
| 64 | ||
| 65 | return [ |
|
| 66 | 'id' => $id, |
|
| 67 | ]; |
|
| 68 | }; |
|
| 69 | } |
|
| 70 | } |
|
| 71 | ||
| @@ 19-70 (lines=52) @@ | ||
| 16 | use WPGraphQL\AppContext; |
|
| 17 | use GraphQL\Error\UserError; |
|
| 18 | ||
| 19 | class TicketCreate |
|
| 20 | { |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Defines the mutation data modification closure. |
|
| 24 | * |
|
| 25 | * @param EEM_Ticket $model |
|
| 26 | * @param Ticket $type |
|
| 27 | * @return callable |
|
| 28 | */ |
|
| 29 | public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
|
| 30 | { |
|
| 31 | /** |
|
| 32 | * Creates an entity. |
|
| 33 | * |
|
| 34 | * @param array $input The input for the mutation |
|
| 35 | * @param AppContext $context The AppContext passed down to all resolvers |
|
| 36 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
| 37 | * |
|
| 38 | * @throws UserError |
|
| 39 | * @throws ReflectionException |
|
| 40 | * @throws InvalidArgumentException |
|
| 41 | * @throws InvalidInterfaceException |
|
| 42 | * @throws InvalidDataTypeException |
|
| 43 | * @throws EE_Error |
|
| 44 | */ |
|
| 45 | return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) |
|
| 46 | { |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Stop now if a user isn't allowed to create a datetime. |
|
| 50 | */ |
|
| 51 | if (! current_user_can('ee_edit_events')) { |
|
| 52 | // translators: the %1$s is the name of the object being mutated |
|
| 53 | throw new UserError(sprintf(__('Sorry, you are not allowed to create %1$s', 'event_espresso' ), $type->name())); |
|
| 54 | } |
|
| 55 | ||
| 56 | $args = TicketMutation::prepare_fields($input); |
|
| 57 | ||
| 58 | $entity = EE_Ticket::new_instance($args); |
|
| 59 | $id = $entity->save(); |
|
| 60 | ||
| 61 | if (empty($id)) { |
|
| 62 | throw new UserError(__( 'The object failed to create but no error was provided', 'event_espresso')); |
|
| 63 | } |
|
| 64 | ||
| 65 | return [ |
|
| 66 | 'id' => $id, |
|
| 67 | ]; |
|
| 68 | }; |
|
| 69 | } |
|
| 70 | } |
|
| 71 | ||