Skip to content

Instantly share code, notes, and snippets.

View reddyweb's full-sized avatar
🎯
Focusing

Sudharshan reddyweb

🎯
Focusing
View GitHub Profile
@reddyweb
reddyweb / using_limit_validation_errors.php
Created April 5, 2022 09:07 — forked from anxp/using_limit_validation_errors.php
How to correctly use #limit_validation_errors element of Form API in Drupal 7
<?php
//Sometimes we need to submit only part of the form. Sure, if form has #required fields, all they will be highlighted with red,
//and form will not be submitted if these elements have no value.
//To workaround this, we can use '#limit_validation_errors' option AND custom submit function for every 'Partial Submit' button.
//Interesting note: when we use '#limit_validation_errors', we will see ALL form fields in _validate function,
//but in _submit function will be visible ONLY elements, included in '#limit_validation_errors' array!!!
//Case 1. The most simple.
//We want to make a 'reset' button, or 'previous step' button, so it must work even if some REQUIRED form elements are empty:
@reddyweb
reddyweb / node.html.twig
Last active November 28, 2021 14:03
Drupal 9 Twig - Field Image Multivalue field with title and alt tags
{% for key, item in node.field_image.value %}
<img src="{{ file_url(content.field_image[key]['#item'].entity.uri.value) }}" alt="{{ item.alt }}" title="{{ item.title }}" />
{# or #}
{{ content.field_image[key] }}
{% endfor %}
@reddyweb
reddyweb / development.services.yml
Created August 25, 2019 09:45
Drupal + Twig debug settings
# Local development services.
#
# To activate this feature, follow the instructions at the top of the
# 'example.settings.local.php' file, which sits next to this file.
parameters:
http.response.debug_cacheability_headers: true
twig.config:
debug: false
auto_reload: true
cache: false
@reddyweb
reddyweb / CRON-Setup.md
Last active July 16, 2019 09:45
UNIX syntax for cron setup. Make sure that the entered time matches the time on the server - Coordinated Universal Time (UTC).

Fields order

 +---------------- minute (0 - 59)
 |  +------------- hour (0 - 23)
 |  |  +---------- day of month (1 - 31)
 |  |  |  +------- month (1 - 12)
 |  |  |  |  +---- day of week (0 - 6) (Sunday=0)
 |  |  |  |  |
 * * * * *
@reddyweb
reddyweb / mysql.md
Last active April 25, 2019 12:06
find out which table has more records mysql

Find out number of records of all tables in MySQL datbase

SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'database_name' order by table_rows;
@reddyweb
reddyweb / .htaccess
Created April 25, 2019 12:01
Load files and documents in local development from prod
# Map files directory with produciton
RewriteRule ^sites/default/files/styles(.*)$ http://exampledomain.com/sites/default/files/styles/$1 [R=301,NC,L]
RewriteRule ^sites/default/files(.*)$ http://exampledomain.com/sites/default/files/$1 [R=301,NC,L]
@reddyweb
reddyweb / https-redirection.md
Last active April 7, 2019 12:42
Enforce redirection to HTTPS

Redirect all traffic from http:// to https://

  • Below both are working fine, so choose any 1 option.

Option 1:

  • In .htaccess file, add below lines right after "RewriteEngine on"
 # Force redirect to HTTPS
@reddyweb
reddyweb / git-basic-commands.md
Last active November 14, 2023 12:49
Git - Command line instructions

Command line instructions

Git global setup

git config --global user.name "NAME"
git config --global user.email "example@gmail.com"

Create a new repository

@reddyweb
reddyweb / README.sh
Last active November 27, 2018 11:18
useful tips
# Git: Feature Branch Flow
git checkout master
git checkout -b develop
git checkout -b feature_branch
#work happens on feature branch
git checkout develop
git merge feature_branch
@reddyweb
reddyweb / .htaccess
Last active January 30, 2020 12:25
WordPress : Set one more level of security for admin area - add additional HTTP password protection.
# keep .htaccess under wp-admin folder, and .htpasswd under project root folder
#example test credentials: admin:admin
SetEnvIf Request_URI ^/path/to/project/root/folder/wp-admin/admin-ajax.php noauth=1
Authtype Basic
AuthName "Restricted Access"
AuthUserFile /path/to/project/root/folder/.htpasswd
Require valid-user
Order Deny,Allow
Deny from all