Removing certain core Gutenberg blocks, allowed_block_types not working - gutenberg-blocks

I am trying to remove core blocks that won't work with my custom theme. I tried using allowed_block_types, but it doesn't seem to work.
I tried using the code in my functions that I found at developer.wordpress.org, but it does not work for me:
function wpdocs_allowed_block_types ( $block_editor_context, $editor_context ) {
if ( ! empty( $editor_context->post ) ) {
return array(
'core/paragraph',
'core/heading',
'core/list',
);
}
return $block_editor_context;
}
add_filter( 'allowed_block_types_all', 'wpdocs_allowed_block_types', 10, 2 );
Does anyone have a solution?
Am I missing a function?

Related

How to get babel to work with new threejs versions

I am having trouble updating threejs to the new es6 class version that they introduced because I am having trouble with babel.
I have the following code where I am extending Object3D
import {
Object3D,
} from "three";
type Props = {
myProp:string
};
export default class MyBox extends Object3D {
constructor(props: Props = {}) {
super();
console.log("HERE");
this.init(props);
console.log("Done");
}
init(props){
// Do stuff
}
Now this works in almost every case just fine, except when I am trying to load it in an ios webview. In that case I drilled down and saw that my code is transpiled to
function e() {
var e,
o = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
return e = n.call(this) || this, console.log("HERE"), e.init(o), console.log("DOne"), e
Which on the ios webview throws an error saying:
TypeError: Cannot call a class constructor without |new|
Which to me means since Object3D is a class it cannot be called like the transpiled version wants to.
{
"presets": ["#babel/preset-flow", ["#babel/preset-env",
{
"targets": ">1%"
}], "#babel/react"],
"plugins": [
"#babel/transform-runtime",
"#babel/plugin-syntax-flow",
"#babel/plugin-transform-flow-strip-types",
"#babel/plugin-proposal-class-properties"]
}
I have tried playing with the targets property and other packages, but have had no luck. My understanding is the threejs is not getting transpiled, whereas the rest of my code is.
Edit: I was wrong about the cause, it was actually due to Meteor build systems misdetecting whether this was a legacy case or not
Answer for me ended up being:
import { setMinimumBrowserVersions } from "meteor/modern-browsers";
setMinimumBrowserVersions(
{
"mobileSafariUI/WKWebView": 10,
},
"classes"
);

React-Native-Webview: Expected nodeHandle to be not null

I am using react-native-webview for rendering a webview. When I navigate from one page to other inside the webview and then try to go back using this.webviewref.goBack() I get the exception of nodeHandle expected to be non-null.
Here is my piece of code
<View style={{ flex: 1 }}>
<Header
headingText={headerText}
onpress={() => {
// this.dispatchCustomEvent(BACK_PRESS);
if (this.canGoBack) {
this.webViewRef.goBack();
} else NavigationActions.pop();
}}
/>
<WebView
source={{ uri: "http://localhost:3001/invite/" }}
bounces={false}
javaScriptEnabled={true}
ref={webViewRef => (this.webViewRef = webViewRef)}
// injectedJavaScript={patchPostMessageJsCode}
onMessage={event => {
const { type, data } = JSON.parse(event.nativeEvent.data);
console.log({ type });
console.log({ data });
this.handleEvent(type, data);
}}
onNavigationStateChange={navState =>
(this.canGoBack = navState.canGoBack)
}
/>
</View>
console logging this.webViewRef shows that the goBack method exists in the weViewRef
The code for which throws the nodeHandle expected to be non-null can be found here https://github.com/react-native-community/react-native-webview/blob/master/src/WebView.ios.tsx
I am unable to understand what is the problem with getWebViewHandle
and why nodeHandle is null.
I had the same problem. It turns out that my react-native version is too low. It requries at least 0.57. After upgraded to 0.59.5 and other dependencies, this problem disappears.
I had the problem too and I found a solution, my solution at leasts.
I had this piece code:
Versions:
"react": "16.11.0"
"react-native": "0.62.2"
"react-native-webview": "^9.4.0"
<WebView
ref={this._setWebviewRef}
onNavigationStateChange={this._handleWebViewNavigationStateChange}
onMessage={this._handleOnMessage}
source={{uri: this.state.dashboardUrl || ''}}
renderLoading={() => <LoadingSpinner />}
startInLoadingState
incognito
/>
where this._setWebviewRef was the next:
_setWebviewRef = (ref) => {
if (ref && !this.props.webviewRef) {
const {goBack} = ref;
goBack && this.props.setWebviewRef({goBack});
}
};
I'm using redux to save goBack method to use it on the typic _handleAndroidBackButton. So as other guys said, i was giving the fu***** nodeHandle expected to be non-null but i was seeing that goBack method exists on _handleAndroidBackButton context.
Debugging i saw that ref WebView method has multiple calls, not just 1 time as i was controlling. So, deleting this condition && !this.props.webviewRef is already working.
Also, I had tried to set my uri 'hardcoded' with the same error, so that not work for me.
PD: don't try to save entire WebView ref on global state, just save what you need our you will have some errors.
The reason for this problem may be that your component has been rendered for a certain condition at the beginning, but after the condition is not satisfied, the modified component is removed, but the reference of the component is not empty. Therefore, when calling the component method, the component method is called, because the component is not empty, but the reference is still not empty, resulting in an error. To adjust the error caused by the above situation, just set the variable referenced by the previous assignment to null when removing the component

How to implement jquery autocomplete using Zend framework 2?

I am looking for examples on how to implement jquery's autocomplete via zend framework 2.
Based on my previous experiences with autocomplete using java and coldfusion, the http response must be only the JSON data. but Zend would normally attach a layout HTML (as defined by the module config). I was thinking of using an empty layout file (contents would be content; ?>) but I'm not sure if this is the correct (i.e. Zend way) of doing this.
I've been searching the net but can't find anything useful.
Can you please help with examples/links/etc? thanks
To create the autocomplete, you need:
Create a controller to respond in json receiving the parameter by get or post.
.
public function searchAction(){
// GET
$Params = $this->params ();
$count = $Params->fromQuery ( 'count', 10 );
$offset = $Params->fromQuery ( 'offset', 0 );
$search = $Params->fromQuery ( 'search', null );
// Mapper
$Search = TableMapper ();
$rs = $Search->search ( search, $count, $offset ));
//I think good idea create an restful service if you have anothers requests
header('Content-Type: application/json');
echo \Zend\Json\Json::encode ( array (
'status' => true,
'data' => $rs,
) );
die (); }
jQuery / Angle collecting the letters typed in the field.
$("#input").keyup(function(event) {
var stt = $(this).val();
/**
The search is route example, you need put correct url/route
**/
$.get( "/search", function( response ) {
if(response.status == true){
$( ".result" ).html( response );
}
});
});
html to show the response
JQUERY copy contents of a textbox to a field while typing
JQuery UI Autocomplete with Zend Framework

image resize zf2

I need to implement image resize functionality (preferably with gd2 library extension) in zend framework 2.
I could not find any component/helper for the same. Any references?
If i want to create one, where should I add it. In older Zend framework, there was a concept of Action Helper, what about Zend framework 2 ?
Please suggest the best solution here.
I currently use Imagine together with Zend Framework 2 to handle this.
Install Imagine: php composer.phar require imagine/Imagine:0.3.*
Create a service factory for the Imagine service (in YourModule::getServiceConfig):
return array(
'invokables' => array(
// defining it as invokable here, any factory will do too
'my_image_service' => 'Imagine\Gd\Imagine',
),
);
Use it in your logic (hereby a small example with a controller):
public function imageAction()
{
$file = $this->params('file'); // #todo: apply STRICT validation!
$width = $this->params('width', 30); // #todo: apply validation!
$height = $this->params('height', 30); // #todo: apply validation!
$imagine = $this->getServiceLocator()->get('my_image_service');
$image = $imagine->open($file);
$transformation = new \Imagine\Filter\Transformation();
$transformation->thumbnail(new \Imagine\Image\Box($width, $height));
$transformation->apply($image);
$response = $this->getResponse();
$response->setContent($image->get('png'));
$response
->getHeaders()
->addHeaderLine('Content-Transfer-Encoding', 'binary')
->addHeaderLine('Content-Type', 'image/png')
->addHeaderLine('Content-Length', mb_strlen($imageContent));
return $response;
}
This is obviously the "quick and dirty" way, since you should do following (optional but good practice for re-usability):
probably handle image transformations in a service
retrieve images from a service
use an input filter to validate files and parameters
cache output (see http://zend-framework-community.634137.n4.nabble.com/How-to-handle-404-with-action-controller-td4659101.html eventually)
Related: Zend Framework - Returning Image/File using Controller
Use a service for this and inject it to controllers needing the functionality.
Here is a module called WebinoImageThumb in Zend Framework 2. Checkout this. It has some great feature such as -
Image Resize
Image crop, pad, rotate, show and save images
Create image reflection
For those who are unable to integrate Imagine properly like me..
I found another solution WebinoImageThumb here which worked perfectly fine with me. Here is little explanation if you don't want to read full documentation :
Run: php composer.phar require webino/webino-image-thumb:dev-develop
and add WebinoImageThumb as active module in config/application.config.php which further looks like :
<?php
return array(
// This should be an array of module namespaces used in the application.
'modules' => array(
'Application',
'WebinoImageThumb'
),
.. below remains the same
Now in your controller action use this through service locator like below :
// at top on your controller
use Zend\Validator\File\Size;
use Zend\Validator\File\ImageSize;
use Zend\Validator\File\IsImage;
use Zend\Http\Request
// in action
$file = $request->getFiles();
$fileAdapter = new \Zend\File\Transfer\Adapter\Http();
$imageValidator = new IsImage();
if ($imageValidator->isValid($file['file_url']['tmp_name'])) {
$fileParts = explode('.', $file['file_url']['name']);
$filter = new \Zend\Filter\File\Rename(array(
"target" => "file/path/to/image." . $fileParts[1],
"randomize" => true,
));
try {
$filePath = $filter->filter($file['file_url'])['tmp_name'];
$thumbnailer = $this->getServiceLocator()
->get('WebinoImageThumb');
$thumb = $thumbnailer->create($filePath, $options = [], $plugins = []);
$thumb->adaptiveResize(540, 340)->save($filePath);
} catch (\Exception $e) {
return new ViewModel(array('form' => $form,
'file_errors' => array($e->getMessage())));
}
} else {
return new ViewModel(array('form' => $form,
'file_errors' => $imageValidator->getMessages()));
}
Good luck..!!
In order to resize uploaded image on the fly you should do this:
public function imageAction()
{
// ...
$imagine = $this->getImagineService();
$size = new \Imagine\Image\Box(150, 150);
$mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
$image = $imagine->open($destinationPath);
$image->thumbnail($size, $mode)->save($destinationPath);
// ...
}
public function getImagineService()
{
if ($this->imagineService === null)
{
$this->imagineService = $this->getServiceLocator()->get('my_image_service');
}
return $this->imagineService;
}

How do I implement EDSDK's EdsSetProgressCallback function properly?

I'm trying to use EdsSetProgressCallback function from Canon EDSDK 2.10 to inform user about image saving completion. I've set inProgressOption parameter to kEdsProgressOption_Done. The problem is, that after successful saving no action is performed. Can you tell me whether I'm implementing this function correctly?
My callback function:
EdsError EDSCALLBACK CManEosDlg::ProgressFunc (EdsUInt32 inPercent, EdsVoid* inContext, EdsBool* outCancel) {
CManEosDlg *pobj = (CManEosDlg *)inContext;
CStatic *pProgress=(CStatic*)pobj->GetDlgItem(IDC_LABEL);
pProgress->SetWindowText("Image saved");
return EDS_ERR_OK;
}
Fragment od image saving function:
EdsStreamRef DstStreamRef;
EdsError err = EdsCreateFileStream( path , kEdsFileCreateDisposition_CreateAlways , kEdsAccess_Write , &DstStreamRef );
if( err == EDS_ERR_OK ) {
err = EdsSetProgressCallback(DstStreamRef, ProgressFunc, kEdsProgressOption_Done, this);
if(err == EDS_ERR_OK) {
err = EdsSaveImage(_imageModel->getImageObject(), inImageType , inSaveSetting , DstStreamRef );
}
}
EdsRelease(DstStreamRef);
Latter returns EDS_ERR_OK from EdsSetProgressCallback but ProgressFunc is never called after image is saved. I've checked it by putting messagebox there ;)
Your code seems to be nice!
Instead of EdsSaveImage try EdsDownload.
I think EdsSaveImage won't send a call for the callback function.
BTW I was wondering, that you got the "Callbacker" working within your namespace:
EdsError EDSCALLBACK CManEosDlg::ProgressFunc
In my project i had to define that without namespace in the top of my "CManEosDlg"-class, as
EdsError EDSCALLBACK ProgressFunc

Resources