1# --
2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/
3# --
4# This software comes with ABSOLUTELY NO WARRANTY. For details, see
5# the enclosed file COPYING for license information (GPL). If you
6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
7# --
8
9package Kernel::System::DynamicField::Driver::Dropdown;
10
11use strict;
12use warnings;
13
14use Kernel::System::VariableCheck qw(:all);
15
16use parent qw(Kernel::System::DynamicField::Driver::BaseSelect);
17
18our @ObjectDependencies = (
19    'Kernel::Config',
20    'Kernel::System::DynamicFieldValue',
21    'Kernel::System::Log',
22    'Kernel::System::Main',
23);
24
25=head1 NAME
26
27Kernel::System::DynamicField::Driver::Dropdown
28
29=head1 DESCRIPTION
30
31DynamicFields Dropdown Driver delegate
32
33=head1 PUBLIC INTERFACE
34
35This module implements the public interface of L<Kernel::System::DynamicField::Backend>.
36Please look there for a detailed reference of the functions.
37
38=head2 new()
39
40usually, you want to create an instance of this
41by using Kernel::System::DynamicField::Backend->new();
42
43=cut
44
45sub new {
46    my ( $Type, %Param ) = @_;
47
48    # allocate new hash for object
49    my $Self = {};
50    bless( $Self, $Type );
51
52    # set field behaviors
53    $Self->{Behaviors} = {
54        'IsACLReducible'               => 1,
55        'IsNotificationEventCondition' => 1,
56        'IsSortable'                   => 1,
57        'IsFiltrable'                  => 1,
58        'IsStatsCondition'             => 1,
59        'IsCustomerInterfaceCapable'   => 1,
60        'IsLikeOperatorCapable'        => 1,
61    };
62
63    # get the Dynamic Field Backend custom extensions
64    my $DynamicFieldDriverExtensions
65        = $Kernel::OM->Get('Kernel::Config')->Get('DynamicFields::Extension::Driver::Dropdown');
66
67    EXTENSION:
68    for my $ExtensionKey ( sort keys %{$DynamicFieldDriverExtensions} ) {
69
70        # skip invalid extensions
71        next EXTENSION if !IsHashRefWithData( $DynamicFieldDriverExtensions->{$ExtensionKey} );
72
73        # create a extension config shortcut
74        my $Extension = $DynamicFieldDriverExtensions->{$ExtensionKey};
75
76        # check if extension has a new module
77        if ( $Extension->{Module} ) {
78
79            # check if module can be loaded
80            if (
81                !$Kernel::OM->Get('Kernel::System::Main')->RequireBaseClass( $Extension->{Module} )
82                )
83            {
84                die "Can't load dynamic fields backend module"
85                    . " $Extension->{Module}! $@";
86            }
87        }
88
89        # check if extension contains more behaviors
90        if ( IsHashRefWithData( $Extension->{Behaviors} ) ) {
91
92            %{ $Self->{Behaviors} } = (
93                %{ $Self->{Behaviors} },
94                %{ $Extension->{Behaviors} }
95            );
96        }
97    }
98
99    return $Self;
100}
101
102sub FieldValueValidate {
103    my ( $Self, %Param ) = @_;
104
105    # Check for valid possible values list.
106    if ( !IsHashRefWithData( $Param{DynamicFieldConfig}->{Config}->{PossibleValues} ) ) {
107        $Kernel::OM->Get('Kernel::System::Log')->Log(
108            Priority => 'error',
109            Message  => "Need PossibleValues in Dropdown DynamicFieldConfig!",
110        );
111        return;
112    }
113
114    # Check for defined value.
115    if ( !defined $Param{Value} ) {
116        $Kernel::OM->Get('Kernel::System::Log')->Log(
117            Priority => 'error',
118            Message  => "Need Value in Dropdown DynamicField!",
119        );
120        return;
121    }
122
123    # Check if value parameter exists in possible values config.
124    if ( length $Param{Value} ) {
125        return if !defined $Param{DynamicFieldConfig}->{Config}->{PossibleValues}->{ $Param{Value} };
126    }
127
128    return 1;
129}
130
1311;
132
133=head1 TERMS AND CONDITIONS
134
135This software is part of the OTRS project (L<https://otrs.org/>).
136
137This software comes with ABSOLUTELY NO WARRANTY. For details, see
138the enclosed file COPYING for license information (GPL). If you
139did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
140
141=cut
142