drupal8-wiki's People
drupal8-wiki's Issues
Nginx 502错误:upstream sent too big header while reading response header from upstream
在nginx conf
里加上
location ~ '\.php$|^/update.php' {
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
...
重载系统Service
举一个例子,现在需要修改用户登录验证用户名密码的逻辑,让drupal登录验证走自定义的实体里去查,这样实现一个UserLogin实体
UserLogin
id
user_login_id
passwod
source
1:首先找到 core/modules/user/src/Form/UserLoginForm.php
可以看到在`validateAuthentication`方法的最后面
`$uid = $this->userAuth->authenticate($form_state->getValue('name'), $password);`
是通过这样来验证用户名密码
再分别看 `create` 方法 和` __construct` 得知 `$this->userAuth` 是因为调用了 user.auth 这个服务得到的。所以我们要做的就是重载 user.auth 这个服务
2:在自定义模块下建一个 ModuleNameServiceProvider
如果模块名为 my_module_name 那么名字为 MyModuleNameServiceProvider
src/ModuleNameServiceProvider.php
<?php
namespace Drupal\como_user_login;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Symfony\Component\DependencyInjection\Reference;
/**
* Defines a class to build a listing of User Login entities.
*
* @ingroup como_user_login
*/
class ComoUserLoginServiceProvider extends ServiceProviderBase {
public function alter(ContainerBuilder $container) {
$definition = $container->getDefinition('user.auth');
$definition->setClass('Drupal\my_module_name\UserAuth')
->addArgument(new Reference('entity_type.manager'), new Reference('password'));
}
}
?>
3:在自定义模块下建一个 UserAuth 继承 Drupal\user\UserAuth 重载 authenticate 方法就好了
4:如果怕被别的模块和你抢夺重载服务,那么可以在 my_module_name.install 里 hook_install 设置权重
module_set_weight('my_module_name', 10);
不将密码框设置为password 防止chrome 自动填充
use Illuminate\Support\Arr;
/**
* 不将密码框设置为password 防止chrome 自动填充
* Implements hook_preprocess_input().
*/
function module_name_preprocess_input(array &$variables) {
$field = $variables['element'];
if ($field['#type'] == 'password') {
$variables['attributes']['type'] = 'text';
$variables['attributes']['autocomplete'] = 'new-password';
$onclick = Arr::get($variables, 'attributes.onclick', '');
if (!empty($onclick)) {
$onclick .= ';';
}
$variables['attributes']['onclick'] = $onclick . 'this.type="password"';
}
}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.