/
AltField.php
85 lines (75 loc) · 1.8 KB
/
AltField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\fieldlayoutelements\assets;
use Craft;
use craft\base\ElementInterface;
use craft\base\Field;
use craft\fieldlayoutelements\TextareaField;
/**
* AltField represents an Alternative Text field that can be included within a volume’s field layout designer.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 4.0.0
*/
class AltField extends TextareaField
{
/**
* @inheritdoc
*/
public string $attribute = 'alt';
/**
* @inheritdoc
*/
public bool $translatable = false;
/**
* @inheritdoc
*/
public bool $requirable = true;
/**
* @inheritdoc
*/
public function __construct($config = [])
{
unset(
$config['attribute'],
$config['autofocus'],
$config['mandatory'],
$config['maxlength'],
$config['requirable'],
$config['translatable'],
);
parent::__construct($config);
}
/**
* @inheritdoc
*/
public function fields(): array
{
$fields = parent::fields();
unset(
$fields['autofocus'],
$fields['mandatory'],
$fields['maxlength'],
$fields['translatable'],
);
return $fields;
}
/**
* @inheritdoc
*/
public function defaultLabel(?ElementInterface $element = null, bool $static = false): ?string
{
return Craft::t('app', 'Alternative Text');
}
/**
* @inheritdoc
*/
protected function translationDescription(?ElementInterface $element = null, bool $static = false): ?string
{
return Field::TRANSLATION_METHOD_SITE;
}
}