-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a File field, like for .pdf uploads #74
Conversation
This still needs a JS component, but it's registered with PHP now.
Copied from the Image field, including the test.
This means that the field will actually display on the front-end.
Like how the File block accepts any file type: https://github.com/WordPress/gutenberg/blob/2f32ec41c3663fa63eae3ed2494a25bda76ab36f/packages/block-library/src/file/edit.js#L205
This was mainly copied from the Image control, so change this now.
Before, there was no e2e test of this.
They're not necessarily images, as they could be files.
This should be a bit easier, it was strange having $image_id.
There were only conflicts in tests/e2e/specs/all-fields.js They were trival, I kept both.
Align it horizontally with the help text.
php/Blocks/Loader.php
Outdated
@@ -72,7 +72,7 @@ public function init() { | |||
*/ | |||
public function register_hooks() { | |||
add_action( 'enqueue_block_editor_assets', [ $this, 'editor_assets' ] ); | |||
add_filter( 'block_categories', [ $this, 'register_categories' ] ); | |||
add_filter( 'block_categories_all', [ $this, 'register_categories' ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to go out before WP 5.8
to prevent the PHP notice.
if ( newImage?.alt ) { | ||
setImageAlt( newImage.alt ); | ||
} else if ( newImage?.source_url ) { // eslint-disable-line camelcase | ||
if ( media?.alt ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this file's diff is just renaming parameters.
Like here, it changes newImage
to media
, as this hook is now used for files and images.
Nice work Ryan! This is working well for me when logged in as an administrator. However, if I log in as a contributor, I see the file field, but it doesn't actually upload the file. This isn't a The main thing I wanted to be sure of was user capabilities work, which they do. I was reading that you need to wrap |
Thanks, @dreamwhisper! Great idea to test it with a contributor, never though of that. Also, good idea to use a |
As Jen mentioned, this can prevent the <MediaUpload> from showing for users that can't upload files.
There was a trivial conflict in Loader.php.
This isn't the right PR to do it in, but I forgot in #85.
If it's OK, I bumped the WP Tested Up To version to 5.8, forgot to do that in #85 |
Changes
.pdf
filesFixes GF-3071
Testing instructions
cd /path/to/wp-content/plugins/genesis-custom-blocks/
git fetch
git checkout add/file-field
composer install && npm i && npm run build
/wp-admin
> Custom Blocks > Add NewAdd a field with the type 'File':
Click Publish
/wp-admin
> Posts > Add NewEnter the name of the block you just created:
In the block, click 'Upload' and upload any
.pdf
fileExpected: The file name displays:
.pdf
, a.zip
, or any number of files