DateFormat
2 days ago
FieldTypeConfigurator
2 days ago
Media
2 days ago
Post
2 days ago
Pro
2 days ago
ActionIcons.php
2 days ago
AttachmentDisplay.php
2 days ago
BaseComponentFactory.php
2 days ago
BeforeAfter.php
2 days ago
BooleanValues.php
2 days ago
CharacterLimit.php
2 days ago
ColumnInfo.php
2 days ago
CommentDisplay.php
2 days ago
CommentLink.php
2 days ago
CommentStatus.php
2 days ago
CustomField.php
2 days ago
CustomFieldFactory.php
2 days ago
DateFormat.php
2 days ago
DateSaveFormat.php
2 days ago
ExifData.php
2 days ago
FieldType.php
2 days ago
FieldTypeFactory.php
2 days ago
FieldTypeFactoryBuilder.php
2 days ago
FileDisplay.php
2 days ago
FileLink.php
2 days ago
FilePreviewSize.php
2 days ago
HiddenInput.php
2 days ago
HiddenLabel.php
2 days ago
ImageSize.php
2 days ago
ImageSizeBase.php
2 days ago
IncludeMissingSizes.php
2 days ago
InputNameAware.php
2 days ago
IsLink.php
2 days ago
IsLinkable.php
2 days ago
IsMultiple.php
2 days ago
Label.php
2 days ago
LinkLabel.php
2 days ago
LinkToMenu.php
2 days ago
LinkablePostProperty.php
2 days ago
MediaLink.php
2 days ago
Message.php
2 days ago
ModalDisplay.php
2 days ago
Name.php
2 days ago
NumberFormat.php
2 days ago
NumberOfItems.php
2 days ago
Password.php
2 days ago
PathScope.php
2 days ago
PostExtendedProperty.php
2 days ago
PostLink.php
2 days ago
PostProperty.php
2 days ago
PostStatus.php
2 days ago
PostStatusIcon.php
2 days ago
PostType.php
2 days ago
PostTypeFactory.php
2 days ago
RelatedUserMetaField.php
2 days ago
SelectOptions.php
2 days ago
Separator.php
2 days ago
SerializedArrayKeys.php
2 days ago
SerializedDisplay.php
2 days ago
StringLimit.php
2 days ago
Taxonomy.php
2 days ago
TaxonomyFactory.php
2 days ago
TermLink.php
2 days ago
TermProperty.php
2 days ago
UseIcon.php
2 days ago
UserLink.php
2 days ago
UserLinkFactory.php
2 days ago
UserProperty.php
2 days ago
VideoDisplay.php
2 days ago
Width.php
2 days ago
WordLimit.php
2 days ago
WordsPerMinute.php
2 days ago
PostExtendedProperty.php
100 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Setting\ComponentFactory; |
| 6 | |
| 7 | use AC; |
| 8 | use AC\Expression\StringComparisonSpecification; |
| 9 | use AC\FormatterCollection; |
| 10 | use AC\Setting\Children; |
| 11 | use AC\Setting\ComponentFactory\DateFormat\Date; |
| 12 | use AC\Setting\ComponentFactory\FieldTypeConfigurator\FieldComponentDirectorFactory; |
| 13 | use AC\Setting\Config; |
| 14 | use AC\Setting\Control\OptionCollection; |
| 15 | use AC\Type\TableScreenContext; |
| 16 | |
| 17 | class PostExtendedProperty extends PostProperty |
| 18 | { |
| 19 | public const PROPERTY_CUSTOM_FIELD = 'custom_field'; |
| 20 | |
| 21 | private FieldComponentDirectorFactory $field_type; |
| 22 | |
| 23 | private CustomFieldFactory $custom_field; |
| 24 | |
| 25 | public function __construct( |
| 26 | StringLimit $string_limit, |
| 27 | ImageSize $image_size, |
| 28 | UserProperty $user_property, |
| 29 | PostStatusIcon $post_status_icon, |
| 30 | Date $date, |
| 31 | CustomFieldFactory $custom_field, |
| 32 | FieldComponentDirectorFactory $field_type |
| 33 | ) { |
| 34 | parent::__construct($string_limit, $image_size, $user_property, $post_status_icon, $date); |
| 35 | |
| 36 | $this->custom_field = $custom_field; |
| 37 | $this->field_type = $field_type; |
| 38 | } |
| 39 | |
| 40 | protected function get_display_options(): OptionCollection |
| 41 | { |
| 42 | $options = parent::get_display_options(); |
| 43 | |
| 44 | $options->add( |
| 45 | new AC\Setting\Control\Type\Option( |
| 46 | __('Custom Field', 'codepress-admin-columns'), |
| 47 | self::PROPERTY_CUSTOM_FIELD, |
| 48 | __('Other', 'codepress-admin-columns') |
| 49 | ) |
| 50 | ); |
| 51 | |
| 52 | return $options; |
| 53 | } |
| 54 | |
| 55 | protected function add_formatters(Config $config, FormatterCollection $formatters): void |
| 56 | { |
| 57 | if ($this->get_input($config)->get_value() === self::PROPERTY_CUSTOM_FIELD) { |
| 58 | $formatters |
| 59 | ->add(new AC\Formatter\Post\Meta((string)$config->get('field', ''))) |
| 60 | ->add(new AC\Formatter\ImplodeRecursive()); |
| 61 | |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | parent::add_formatters($config, $formatters); |
| 66 | } |
| 67 | |
| 68 | protected function get_children(Config $config): ?Children |
| 69 | { |
| 70 | $parent_children = parent::get_children($config); |
| 71 | |
| 72 | if (! $parent_children) { |
| 73 | return null; |
| 74 | } |
| 75 | |
| 76 | $components = $parent_children->get_iterator(); |
| 77 | |
| 78 | $table_screen_context = new TableScreenContext( |
| 79 | AC\MetaType::create_post_meta(), |
| 80 | ); |
| 81 | |
| 82 | $components->add( |
| 83 | $this->custom_field->create($table_screen_context)->create( |
| 84 | $config, |
| 85 | StringComparisonSpecification::equal('custom_field') |
| 86 | ) |
| 87 | ); |
| 88 | |
| 89 | $components->add( |
| 90 | $this->field_type->add_basic()->create( |
| 91 | $config, |
| 92 | StringComparisonSpecification::equal('custom_field') |
| 93 | ) |
| 94 | ); |
| 95 | |
| 96 | return new Children($components); |
| 97 | } |
| 98 | |
| 99 | } |
| 100 |